def test_relations(self): n_spatial_orbitals = 2 s_plus = s_plus_operator(n_spatial_orbitals) s_minus = s_minus_operator(n_spatial_orbitals) sx = sx_operator(n_spatial_orbitals) sy = sy_operator(n_spatial_orbitals) sz = sz_operator(n_spatial_orbitals) s_squared = s_squared_operator(n_spatial_orbitals) identity = FermionOperator(()) self.assertEqual(normal_ordered(sx), normal_ordered(.5 * (s_plus + s_minus))) self.assertEqual(normal_ordered(sy), normal_ordered((.5 / 1.j) * (s_plus - s_minus))) self.assertEqual(normal_ordered(s_squared), normal_ordered(sx**2 + sy**2 + sz**2)) self.assertEqual( normal_ordered(s_squared), normal_ordered(s_plus * s_minus + sz * (sz - identity))) self.assertEqual(normal_ordered(commutator(s_plus, s_minus)), normal_ordered(2 * sz)) self.assertEqual(normal_ordered(commutator(sx, sy)), normal_ordered(1.j * sz))
def test_invalid_input(self): with self.assertRaises(TypeError): s_minus_operator('a') with self.assertRaises(TypeError): s_plus_operator('a') with self.assertRaises(TypeError): sx_operator('a') with self.assertRaises(TypeError): sy_operator('a') with self.assertRaises(TypeError): sz_operator('a') with self.assertRaises(TypeError): s_squared_operator('a')
def test_s_squared_operator(self): op = s_squared_operator(2) s_minus = (FermionOperator(((1, 1), (0, 0))) + FermionOperator( ((3, 1), (2, 0)))) s_plus = (FermionOperator(((0, 1), (1, 0))) + FermionOperator( ((2, 1), (3, 0)))) s_z = (FermionOperator(((0, 1), (0, 0)), 0.5) - FermionOperator( ((1, 1), (1, 0)), 0.5) + FermionOperator( ((2, 1), (2, 0)), 0.5) - FermionOperator(((3, 1), (3, 0)), 0.5)) expected = s_minus * s_plus + s_z * s_z + s_z self.assertEqual(op, expected)
def test_uccsd_singlet_symmetries(self): """Test that the singlet generator has the correct symmetries.""" test_orbitals = 8 test_electrons = 4 packed_amplitude_size = uccsd_singlet_paramsize( test_orbitals, test_electrons) packed_amplitudes = randn(int(packed_amplitude_size)) generator = uccsd_singlet_generator(packed_amplitudes, test_orbitals, test_electrons) # Construct symmetry operators sz = sz_operator(test_orbitals) s_squared = s_squared_operator(test_orbitals) # Check the symmetries comm_sz = normal_ordered(commutator(generator, sz)) comm_s_squared = normal_ordered(commutator(generator, s_squared)) zero = FermionOperator() self.assertEqual(comm_sz, zero) self.assertEqual(comm_s_squared, zero)