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)
     for i in range(2 * self.n_qubits):
         if i < self.n_qubits:
             left_op = majorana_operator((i, 1))
         else:
             left_op = majorana_operator((i - self.n_qubits, 0))
         for j in range(2 * self.n_qubits):
             if j < self.n_qubits:
                 right_op = majorana_operator((j, 1), majorana_matrix[i, j])
             else:
                 right_op = majorana_operator((j - self.n_qubits, 0),
                                              majorana_matrix[i, j])
             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).isclose(fermion_operator))
 def test_bad_coefficient(self):
     with self.assertRaises(ValueError):
         majorana_op = majorana_operator((1, 1), 'a')
 def test_bad_term(self):
     with self.assertRaises(ValueError):
         majorana_op = majorana_operator((2, 2))
     with self.assertRaises(ValueError):
         majorana_op = majorana_operator('a')
 def test_none_term(self):
     majorana_op = majorana_operator()
     self.assertTrue(majorana_operator().isclose(FermionOperator()))