From 8aeffbb719065490ae3be08e89ea30e5703fa78c Mon Sep 17 00:00:00 2001 From: Tyler Hughes Date: Wed, 12 Jun 2024 16:46:59 -0400 Subject: [PATCH] add test --- tests/test_components/test_autograd.py | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/test_components/test_autograd.py b/tests/test_components/test_autograd.py index b96e4f954..ecc576d03 100644 --- a/tests/test_components/test_autograd.py +++ b/tests/test_components/test_autograd.py @@ -1,5 +1,6 @@ # test autograd integration into tidy3d +import copy import cProfile import typing from importlib import reload @@ -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."""