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)
def test_bad_term(self): with self.assertRaises(ValueError): majorana_operator((2, 2)) with self.assertRaises(ValueError): majorana_operator('a') with self.assertRaises(ValueError): majorana_operator(2)
def test_init(self): # Test 'c' operator op1 = majorana_operator((2, 0)) op2 = majorana_operator('c2') op3 = majorana_operator(u'c2') correct = FermionOperator('2^') + FermionOperator('2') self.assertEqual(op1, op2) self.assertEqual(op1, op3) self.assertEqual(op1, correct) # Test 'd' operator op1 = majorana_operator((3, 1)) op2 = majorana_operator('d3') correct = FermionOperator('3^', 1.j) - FermionOperator('3', 1.j) self.assertEqual(op1, op2) self.assertEqual(op1, correct) with self.assertRaises(ValueError): _ = majorana_operator('A2')
def test_bad_coefficient(self): with self.assertRaises(ValueError): majorana_operator((1, 1), 'a')
def test_none_term(self): majorana_operator() self.assertEqual(majorana_operator(), FermionOperator())
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