The non-Markovian stochastic Schrödinger equation for open systems