Exemple #1
0
 def pair_unitary(a, b):
     '''
     Accepts a BinaryPauliString. 
     Return the paired unitary 1/sqrt(2) (a + b) in qubit hamiltonian. 
     '''
     a = QubitHamiltonian.from_paulistrings(a.to_pauli_strings())
     b = QubitHamiltonian.from_paulistrings(b.to_pauli_strings())
     return (1 / 2) ** (1 / 2) * (a + b)
def test_paulistring_conversion():
    X1 = QubitHamiltonian.from_string("X0", openfermion_format=True)
    X2 = paulis.X(0)
    keys = [i for i in X2.keys()]
    pwx = PauliString.from_openfermion(key=keys[0], coeff=X2[keys[0]])
    X3 = QubitHamiltonian.from_paulistrings(pwx)
    assert (X1 == X2)
    assert (X2 == X3)

    H = paulis.X(0) * paulis.Y(1) * paulis.Z(2) + paulis.X(3) * paulis.Y(
        4) * paulis.Z(5)
    PS = []
    for key, value in H.items():
        PS.append(PauliString.from_openfermion(key, value))
    PS2 = H.paulistrings
    assert (PS == PS2)

    H = make_random_pauliword(complex=True)
    for i in range(5):
        H += make_random_pauliword(complex=True)
    PS = []
    for key, value in H.items():
        PS.append(PauliString.from_openfermion(key, value))
    PS2 = H.paulistrings
    assert (PS == PS2)
Exemple #3
0
 def __init__(self,
              paulistring: PauliString,
              angle: float,
              control: typing.List[int] = None):
     super().__init__(eigenvalues_magnitude=0.5,
                      name="Exp-Pauli",
                      target=tuple(t for t in paulistring.keys()),
                      control=control,
                      parameter=angle)
     self.paulistring = paulistring
     self.generator = QubitHamiltonian.from_paulistrings(paulistring)
     self.finalize()
Exemple #4
0
 def to_qubit_hamiltonian(self):
     qub_ham = QubitHamiltonian()
     for p in self.binary_terms:
         qub_ham += QubitHamiltonian.from_paulistrings(p.to_pauli_strings())
     return qub_ham