Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerflex authored and momchil-flex committed Jun 13, 2024
1 parent 961978e commit 8aeffbb
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/test_components/test_autograd.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# test autograd integration into tidy3d

import copy
import cProfile
import typing
from importlib import reload
Expand Down Expand Up @@ -686,6 +687,34 @@ def objective(*args):
ag.grad(objective)(params0)


def test_autograd_deepcopy():
"""make sure deepcopy works as expected in autograd."""

def post(x, y):
return 3 * x + y

def f1(x):
y = copy.deepcopy(x)
return post(x, y)

def f2(x):
y = copy.copy(x)
return post(x, y)

def f3(x):
y = x
return post(x, y)

x0 = 12.0

val1, grad1 = ag.value_and_grad(f1)(x0)
val2, grad2 = ag.value_and_grad(f2)(x0)
val3, grad3 = ag.value_and_grad(f3)(x0)

assert val1 == val2 == val3
assert grad1 == grad2 == grad3


# @pytest.mark.timeout(18.0)
# def test_many_structures_timeout():
# """Test that a metalens-like simulation with many structures can be initialized fast enough."""
Expand Down

0 comments on commit 8aeffbb

Please sign in to comment.