The updated error should point at the line that is doing an inplace operation that is not allowed.
But for the code above, I think changing     z = torch.zeros( nObservations, requires_grad = True ) to     z = torch.zeros( nObservations) should work.