Any way to perform forward pass by utilizing the DAG created?

Hi all,

I have the following program:

  1. create a vector x.
  2. Perform a finite-element physical simulation on x to obtain P. (P = f(x)). I make a DAG of interactions the environment makes on x.
  3. Compute error, E. (E = ||P_actual - P_simulated||^2 )
  4. Compute ∇E wrt x using E.backward()
  5. Update x using optimizer.step()
  6. Repeat steps 2 to 5.

The problem is, step 2 (the finite element simulation) takes way too much time to run everytime. Is there a method available that allows me to directly compute E by using the DAG already present? Since the DAG is used to compute the gradient, it should also allow me to perform a “forward pass” that completely bypasses having to run the finite-element simulation for every iteration, right?

So in essence, I simply wish to just run the finite-element simulation once to get a DAG, and use that DAG to perform my computations for every subsequent iteration.

Thanks! :slight_smile: