def test_ladder_wrong_form(self): """Test exception raised for wrong ladder operators""" with pytest.raises(BoseHubbardError): H = bose_hubbard(2, 2, 1, 1, 1, 0.5) H += BosonOperator('5^ 5 6^ 6^') H -= BosonOperator('6 5') extract_dipole(H)
def test_coefficients_differ(self): """Test exception raised for differing coefficients""" self.logTestName() with self.assertRaises(BoseHubbardError): H = BosonOperator('0^ 0 1^ 1', 0.5) H += BosonOperator('0^ 0 2^ 2', 1) extract_dipole(H)
def test_too_many_terms(self): """Test exception raised for wrong number of terms""" self.logTestName() with self.assertRaises(BoseHubbardError): H = bose_hubbard(2, 2, 1, 1, 1, 0.5) H += BosonOperator('0^ 0 1^ 2', 0.5) extract_dipole(H)
def test_2x2(self): """Test extracted dipole terms on 2x2 grid""" H = bose_hubbard(2, 2, 1, 0, 0, 0.5) res = extract_dipole(H) res[0] = sorted(res[0], key=lambda x: x[0]) expected = [[(0, 1), (0, 2), (1, 3), (2, 3)], 0.5] assert res == expected
def test_arbitrary(self): """Test extracted dipole terms on arbitrary grid""" self.logTestName() H = BosonOperator('0^ 0 5^ 5', 0.1) res = extract_dipole(H) expected = [[(0, 5)], 0.1] self.assertEqual(res, expected)
def test_2x2(self): """Test extracted dipole terms on 2x2 grid""" self.logTestName() H = bose_hubbard(2, 2, 1, 0, 0, 0.5) res = extract_dipole(H) res[0] = sorted(res[0], key=lambda x: x[0]) expected = [[(0, 1), (0, 2), (1, 3), (2, 3)], 0.5] self.assertEqual(res, expected)
def test_arbitrary(self): """Test extracted dipole terms on arbitrary grid""" H = BosonOperator('0^ 0 5^ 5', 0.1) res = extract_dipole(H) expected = [[(0, 5)], 0.1] assert res == expected
def test_coefficients_differ(self): """Test exception raised for differing coefficients""" with pytest.raises(BoseHubbardError): H = BosonOperator('0^ 0 1^ 1', 0.5) H += BosonOperator('0^ 0 2^ 2', 1) extract_dipole(H)
def test_no_dipole(self): """Test case where there is zero V""" H = bose_hubbard(2, 2, 1, 1, 1, 0) res = extract_dipole(H) assert res == []
def test_no_dipole(self): """Test case where there is zero V""" self.logTestName() H = bose_hubbard(2, 2, 1, 1, 1, 0) res = extract_dipole(H) self.assertEqual(res, [])
def test_2x2(self): """Test extracted dipole terms on 2x2 grid""" H = bose_hubbard(2, 2, 1, 0, 0, 0.5) res = extract_dipole(H) expected = [[(0, 1), (0, 2), (1, 3), (2, 3)], 0.5] self.assertEqual(res, expected)