Exemple #1
0
    def _operator_generator(index, conj):
        """
        Internal method to generate the appropriate operator
        """
        pterm = PauliTerm('I', 0, 1.0)
        Zstring = PauliTerm('I', 0, 1.0)
        for j in range(index):
            Zstring = Zstring * PauliTerm('Z', j, 1.0)

        pterm1 = Zstring * PauliTerm('X', index, 0.5)
        scalar = 0.5 * conj * 1.0j
        pterm2 = Zstring * PauliTerm('Y', index, scalar)
        pterm = pterm * (pterm1 + pterm2)

        pterm = pterm.simplify()
        return pterm
Exemple #2
0
    def product_ops(self, indices, conjugate):
        """
        Convert a list of site indices and coefficients to a Pauli Operators
        list with the generalized Bravyi-Kitaev transformation.

        :param list indices: list of ints specifying the site the fermionic
                             operator acts on, e.g. [0,2,4,6]
        :param list conjugate: List of -1, 1 specifying which of the indices
                               are creation operators (-1) and which are
                               annihilation operators (1).  e.g. [-1,-1,1,1]
        """
        pterm = PauliTerm('I', 0, 1.0)
        for conj, index in zip(conjugate, indices):
            pterm = pterm * self._operator_generator(index, conj)

        pterm = pterm.simplify()
        return pterm
Exemple #3
0
def test_zero_terms():
    term = PauliTerm("X", 0, 1.0) + PauliTerm("X", 0, -1.0) + PauliTerm("Y", 0, 0.5)
    assert str(term) == "(0.5+0j)*Y0"

    term = PauliTerm("X", 0, 1.0) + PauliTerm("X", 0, -1.0)
    assert str(term) == "0j*I"
    assert len(term.terms) == 1

    term2 = term * PauliTerm("Z", 2, 0.5)
    assert str(term2) == "0j*I"

    term3 = PauliTerm("Z", 2, 0.5) + term
    assert str(term3) == "(0.5+0j)*Z2"

    term4 = PauliSum([])
    assert str(term4) == "0j*I"

    term = PauliSum([PauliTerm("X", 0, 0.0), PauliTerm("Y", 1, 1.0) * PauliTerm("Z", 2)])
    assert str(term) == "0j*X0 + (1+0j)*Y1*Z2"
    term = term.simplify()
    assert str(term) == "(1+0j)*Y1*Z2"