Skip to content

Commit 0e56b35

Browse files
yaugenst-flexdaquinteroflex
authored andcommitted
remove more adjoint plugin references
1 parent c6bfb0e commit 0e56b35

File tree

5 files changed

+15
-40
lines changed

5 files changed

+15
-40
lines changed

docs/install.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ Tidy3D also offers plugins that require additional dependencies:
205205

206206
- ``design``: Design space exploration and optimization.
207207
- ``pytorch``: A PyTorch wrapper for objective functions defined using autograd.
208-
- ``adjoint``: Adjoint optimization using JAX (deprecated in favor of native autograd support in Tidy3D)
209208

210209
For example, to install the design plugin dependencies:
211210

tidy3d/plugins/autograd/README.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ This functionality was previously available using the `adjoint` plugin, which us
1111
3. Because we inherited these classes from their `tidy3d` components, for technical reasons, we needed to separate the `jax`-traced fields from the regular fields.
1212
For example, `JaxSimulation.input_structures` and `.output_monitors` were needed.
1313

14-
All of these limitations (among others) motivated us to come up with a new approach to automatic differentiation, which was introduced as an experimental feature in `2.7`.
15-
The `adjoint` plugin will continue to be supported indefinitely, but no new features will be developed for it.
16-
We also believe the new approach offers a far better user experience, so we encourage users to switch whenever is convenient.
17-
This guide will give some instructions on how to do so.
14+
All of these limitations (among others) motivated us to come up with a new approach to automatic differentiation, which was introduced as an experimental feature in `2.7` and is now the default.
15+
The previous JAX-based `adjoint` plugin has been removed in favor of this built-in workflow.
16+
This guide will give some instructions on how to migrate existing code.
1817

1918
## New implementation using `autograd`
2019

@@ -89,18 +88,12 @@ Additionally, `autograd` has a `grad_with_aux` function that can be used to comp
8988

9089
Otherwise, `jax` and `autograd` are very similar to each other in practice.
9190

92-
### Migrating from `adjoint` plugin
91+
### Migrating from the deprecated `adjoint` plugin
9392

9493
Converting code from the `adjoint` plugin to the native autograd support is straightforward.
9594

96-
Instead of importing classes from the `tda` namespace, with names like `tda.Jax_`, we can just use regular `td.` classes.
97-
98-
```py
99-
import tidy3d.plugins.adjoint as tda
100-
tda.JaxStructure(...)
101-
```
102-
103-
becomes
95+
Instead of importing classes from the old `tidy3d.plugins.adjoint` namespace (for example `tda.JaxStructure`),
96+
you can use the regular `tidy3d` classes directly:
10497

10598
```py
10699
import tidy3d as td

tidy3d/plugins/invdes/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
This describes the "Inverse Design" (`invdes`) plugin of Tidy3D.
66

7-
The goal of `invdes` is to provide a simpler interface for setting up most practical inverse design problems. It wraps the lower-level `adjoint` plugin of Tidy3D to perform the gradient calculations, but allows the user to focus on the important aspects of their design without getting into the details of `autograd`.
7+
The goal of `invdes` is to provide a simpler interface for setting up most practical inverse design problems. It leverages Tidy3D's native autograd-based adjoint infrastructure to perform the gradient calculations, while allowing the user to focus on the important aspects of their design without getting into low-level workflow details.
88

99
In this notebook, we'll give a simple demo showing the inverse design of a 1 -> 3 splitter using the inverse design plugin.
1010

@@ -97,7 +97,7 @@ Next we want to define the base `td.Simulation` that contains the static portion
9797

9898
For this, we will make a bunch of regular `tidy3d` components (excluding the design region) and put them into a `td.Simulation`.
9999

100-
> Note: we don't need to use `adjoint` components, such as `td.Simulation` in the `invdes` plugin. These components are created behind the scenes by the higher level wrappers that we define here.
100+
> Note: there is no need to use any special autograd-specific component classes in user code; the plugin builds the differentiable structures internally from the standard `td.*` objects defined here.
101101
102102
```py
103103

@@ -285,7 +285,7 @@ design = tdi.InverseDesign(
285285
output_monitor_names=[mnt.name for mnt in monitors_out],
286286
)
287287
```
288-
> Note: the `output_monitor_names` field is used to specify which monitors to use in the objective function. If they are not supplied, `invdes` will automatically include all compatible monitors, but at times these can raise warnings in the `adjoint` plugin, so it can be nice to specify.
288+
> Note: the `output_monitor_names` field is used to specify which monitors to use in the objective function. If they are not supplied, `invdes` will automatically include all compatible monitors, but at times these can raise warnings if the differentiable workflow cannot trace certain monitor types, so it can be nice to specify.
289289
290290
The `InverseDesign` object can be exported to a `td.Simulation` given some parameters using the `to_simulation(params)` method.
291291

tidy3d/plugins/invdes/design.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,9 @@ class InverseDesign(AbstractInverseDesign):
128128
None,
129129
title="Output Monitor Names",
130130
description="Optional names of monitors whose data the differentiable output depends on."
131-
"If this field is left ``None``, the plugin will try to add all compatible monitors to "
132-
"``JaxSimulation.output_monitors``. While this will work, there may be warnings if the "
133-
"monitors are not compatible with the ``adjoint`` plugin, for example if there are "
134-
"``FieldMonitor`` instances with ``.colocate != False``.",
131+
"If this field is left ``None``, the plugin will try to add all compatible monitors "
132+
"automatically. While this will work, there may be warnings if certain monitor types are "
133+
"not fully supported, for example ``FieldMonitor`` instances with ``.colocate != False``.",
135134
)
136135

137136
_check_sim_pixel_size = check_pixel_size("simulation")
@@ -270,10 +269,9 @@ class InverseDesignMulti(AbstractInverseDesign):
270269
None,
271270
title="Output Monitor Names",
272271
description="Optional names of monitors whose data the differentiable output depends on."
273-
"If this field is left ``None``, the plugin will try to add all compatible monitors to "
274-
"``JaxSimulation.output_monitors``. While this will work, there may be warnings if the "
275-
"monitors are not compatible with the ``adjoint`` plugin, for example if there are "
276-
"``FieldMonitor`` instances with ``.colocate != False``.",
272+
"If this field is left ``None``, the plugin will try to add all compatible monitors "
273+
"automatically. While this will work, there may be warnings if certain monitor types are "
274+
"not fully supported, for example ``FieldMonitor`` instances with ``.colocate != False``.",
277275
)
278276

279277
_check_sim_pixel_size = check_pixel_size("simulations")

tidy3d/web/core/task_core.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from datetime import datetime
1010
from typing import Callable, Optional, Union
1111

12-
import pydantic.v1 as pd
1312
from botocore.exceptions import ClientError
1413
from pydantic.v1 import Extra, Field, parse_obj_as
1514

@@ -200,20 +199,6 @@ class SimulationTask(ResourceLifecycle, Submittable, extra=Extra.allow):
200199
# description="List of parent task ids for the simulation, used internally only."
201200
# )
202201

203-
@pd.root_validator(pre=True)
204-
def _error_if_jax_sim(cls, values):
205-
"""Raise error if user tries to submit simulation that's a JaxSimulation."""
206-
sim = values.get("simulation")
207-
if sim is None:
208-
return values
209-
if "JaxSimulation" in str(type(sim)):
210-
raise ValueError(
211-
"'JaxSimulation' not compatible with regular webapi functions. "
212-
"Either convert it to Simulation with 'jax_sim.to_simulation()[0]' or use "
213-
"the 'adjoint.run' function to run JaxSimulations."
214-
)
215-
return values
216-
217202
@classmethod
218203
def create(
219204
cls,

0 commit comments

Comments
 (0)