The phase retrieval problem of coherence theory as a stability problem