Universal loss and gain characterization inside photonic integrated circuits | Synapse