def expect_oper(self, state, lindbladian, oper): if lindbladian: rho = tf_utils.tf_vec_to_dm(state) else: rho = tf_utils.tf_state_to_dm(state) trace = np.trace(np.matmul(rho, oper)) return [[np.real(trace)]] # ,[np.imag(trace)]]
def populations(self, state, lindbladian): """ Compute populations from a state or density vector. Parameters ---------- state: tf.Tensor State or densitiy vector. lindbladian: boolean Specify if conversion to density matrix is needed. Returns ------- tf.Tensor Vector of populations. """ if lindbladian: rho = tf_utils.tf_vec_to_dm(state) pops = tf.math.real(tf.linalg.diag_part(rho)) return tf.reshape(pops, shape=[pops.shape[0], 1]) else: return tf.abs(state)**2