def test_sz_operator(self): op = sz_operator(2) expected = (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)) self.assertTrue(op.isclose(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)
def test_sz_operator_invalid_input(self): with self.assertRaises(TypeError): sz_operator('A')