bernstein_vazirani.py 文件源码

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

项目:grove 作者: rigetticomputing 项目源码 文件源码
def create_bv_bitmap(dot_product_vector, dot_product_bias):
    """
    This function creates a map from bitstring to function value for a boolean formula :math:`f`
    with a dot product vector :math:`a` and a dot product bias :math:`b`

        .. math::

           f:\\{0,1\\}^n\\rightarrow \\{0,1\\}

           \\mathbf{x}\\rightarrow \\mathbf{a}\\cdot\\mathbf{x}+b\\pmod{2}

           (\\mathbf{a}\\in\\{0,1\\}^n, b\\in\\{0,1\\})

    :param String dot_product_vector: a string of 0's and 1's that represents the dot-product
        partner in :math:`f`
    :param String dot_product_bias: 0 or 1 as a string representing the bias term in :math:`f`
    :return: A dictionary containing all possible bitstring of length equal to :math:`a` and the
        function value :math:`f`
    :rtype: Dict[String, String]
    """
    n_bits = len(dot_product_vector)
    bit_map = {}
    for bit_val in range(2 ** n_bits):
        bit_map[np.binary_repr(bit_val, width=n_bits)] = str(
            (int(utils.bitwise_dot_product(np.binary_repr(bit_val, width=n_bits),
                                           dot_product_vector))
             + int(dot_product_bias, 2)) % 2
        )

    return bit_map
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号