| 9 | |
| 10 | |
| 11 | class TestCollectionState(unittest.TestCase): |
| 12 | def test_forward(self): |
| 13 | for dtype in DTYPES: |
| 14 | eps = EPS[dtype] |
| 15 | for device in DEVICES: |
| 16 | f, y0, t_points, sol = construct_problem(dtype=dtype, device=device) |
| 17 | tuple_f = lambda t, y: (f(t, y[0]), f(t, y[1])) |
| 18 | tuple_y0 = (y0, y0) |
| 19 | for method in ADAPTIVE_METHODS: |
| 20 | |
| 21 | with self.subTest(dtype=dtype, device=device, method=method): |
| 22 | tuple_y = torchdiffeq.odeint(tuple_f, tuple_y0, t_points, method=method) |
| 23 | max_error0 = (sol - tuple_y[0]).abs().max() |
| 24 | max_error1 = (sol - tuple_y[1]).abs().max() |
| 25 | self.assertLess(max_error0, eps) |
| 26 | self.assertLess(max_error1, eps) |
| 27 | |
| 28 | def test_gradient(self): |
| 29 | for device in DEVICES: |
| 30 | f, y0, t_points, sol = construct_problem(device=device) |
| 31 | tuple_f = lambda t, y: (f(t, y[0]), f(t, y[1])) |
| 32 | for method in ADAPTIVE_METHODS: |
| 33 | if method == "scipy_solver": |
| 34 | continue |
| 35 | |
| 36 | with self.subTest(device=device, method=method): |
| 37 | for i in range(2): |
| 38 | func = lambda y0, t_points: torchdiffeq.odeint(tuple_f, (y0, y0), t_points, method=method)[i] |
| 39 | self.assertTrue(torch.autograd.gradcheck(func, (y0, t_points))) |
| 40 | |
| 41 | |
| 42 | if __name__ == '__main__': |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…