Gradient of stacked forward passes?


I’m trying to write a pytorch model that flies an aircraft to the point (0,0,0)

The loss function looks approximately like this:

aircraft_state = get_initial_state() ← position, velocity, etc.
pilot_decision = get_initial_pilot_decision() ← constant thrust forward

for i in range(number_of_time_steps):
pilot_decision = model(aircraft_state)
aircraft_state = iterate_state(pilot_decision) ← moves the aircraft based on the pilot decision

loss = aircraft_state.get_position().get_norm()

After implementation, I found that this isn’t working. I’m not exactly sure what it does, but the loss changes very little when I start the training.
Could it be that only the last forward pass in the for loop is used for the backpropagation?
Is there a way to get pytorch to calculate the gradient based on all consecutive model calls?