_pysim.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:ProjectQ 作者: ProjectQ-Framework 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号