Esempio n. 1
0
 def test_majorana_form(self):
     """Test getting the Majorana form."""
     majorana_matrix, majorana_constant = self.quad_ham_npc.majorana_form()
     # Convert the Majorana form to a FermionOperator
     majorana_op = FermionOperator((), majorana_constant)
     normalization = 1. / numpy.sqrt(2.)
     for i in range(2 * self.n_qubits):
         if i < self.n_qubits:
             left_op = majorana_operator((i, 0), normalization)
         else:
             left_op = majorana_operator((i - self.n_qubits, 1),
                                         normalization)
         for j in range(2 * self.n_qubits):
             if j < self.n_qubits:
                 right_op = majorana_operator(
                     (j, 0), majorana_matrix[i, j] * normalization)
             else:
                 right_op = majorana_operator(
                     (j - self.n_qubits, 1),
                     majorana_matrix[i, j] * normalization)
             majorana_op += .5j * left_op * right_op
     # Get FermionOperator for original Hamiltonian
     fermion_operator = normal_ordered(
         get_fermion_operator(self.quad_ham_npc))
     self.assertTrue(normal_ordered(majorana_op) == fermion_operator)
Esempio n. 2
0
def stabilizer(i, j):
    """Stabilizer operators which act on the auxiliary space.
    In the original paper, these are referred to as P_{ij}."""
    c_i = majorana_operator((i, 0))
    d_j = majorana_operator((j, 1))
    return 1.j * c_i * d_j
Esempio n. 3
0
 def test_bad_coefficient(self):
     with self.assertRaises(ValueError):
         majorana_op = majorana_operator((1, 1), 'a')
Esempio n. 4
0
 def test_bad_term(self):
     with self.assertRaises(ValueError):
         majorana_op = majorana_operator((2, 2))
     with self.assertRaises(ValueError):
         majorana_op = majorana_operator('a')
Esempio n. 5
0
 def test_none_term(self):
     majorana_op = majorana_operator()
     self.assertTrue(majorana_operator().isclose(FermionOperator()))