(device, npts=10, ode='constant', reverse=False, dtype=torch.float64)
| 77 | |
| 78 | |
| 79 | def construct_problem(device, npts=10, ode='constant', reverse=False, dtype=torch.float64): |
| 80 | |
| 81 | f = PROBLEMS[ode]().to(dtype=dtype, device=device) |
| 82 | |
| 83 | t_points = torch.linspace(1, 8, npts, dtype=torch.float64, device=device, requires_grad=True) |
| 84 | sol = f.y_exact(t_points).to(dtype) |
| 85 | |
| 86 | def _flip(x, dim): |
| 87 | indices = [slice(None)] * x.dim() |
| 88 | indices[dim] = torch.arange(x.size(dim) - 1, -1, -1, dtype=torch.long, device=device) |
| 89 | return x[tuple(indices)] |
| 90 | |
| 91 | if reverse: |
| 92 | t_points = _flip(t_points, 0).clone().detach() |
| 93 | sol = _flip(sol, 0).clone().detach() |
| 94 | |
| 95 | return f, sol[0].detach().requires_grad_(True), t_points, sol |
| 96 | |
| 97 | |
| 98 | if __name__ == '__main__': |
searching dependent graphs…