def get_expectation_value(self, terms_dict, ids):
"""
Return the expectation value of a qubit operator w.r.t. qubit ids.
Args:
terms_dict (dict): Operator dictionary (see QubitOperator.terms)
ids (list[int]): List of qubit ids upon which the operator acts.
Returns:
Expectation value
"""
expectation = 0.
current_state = _np.copy(self._state)
for (term, coefficient) in terms_dict:
self._apply_term(term, ids)
delta = coefficient * _np.vdot(current_state, self._state).real
expectation += delta
self._state = _np.copy(current_state)
return expectation
评论列表
文章目录