def test_plane_wave_hamiltonian_integration(self): length_set = [3, 4] spinless_set = [True, False] geometry = [('H', (0, )), ('H', (0.8, ))] length_scale = 1.1 for l in length_set: for spinless in spinless_set: grid = Grid(dimensions=1, scale=length_scale, length=l) h_plane_wave = plane_wave_hamiltonian(grid, geometry, spinless, True, include_constant=True) h_dual_basis = plane_wave_hamiltonian(grid, geometry, spinless, False) jw_h_plane_wave = jordan_wigner(h_plane_wave) jw_h_dual_basis = jordan_wigner(h_dual_basis) h_plane_wave_spectrum = eigenspectrum(jw_h_plane_wave) h_dual_basis_spectrum = eigenspectrum(jw_h_dual_basis) max_diff = numpy.amax(h_plane_wave_spectrum - h_dual_basis_spectrum) min_diff = numpy.amin(h_plane_wave_spectrum - h_dual_basis_spectrum) self.assertAlmostEqual(max_diff, 2.8372 / length_scale) self.assertAlmostEqual(min_diff, 2.8372 / length_scale)
def test_inverse_fourier_transform_2d(self): grid = Grid(dimensions=2, scale=1.5, length=3) spinless = True geometry = [('H', (0, 0)), ('H', (0.5, 0.8))] h_plane_wave = plane_wave_hamiltonian(grid, geometry, spinless, True) h_dual_basis = plane_wave_hamiltonian(grid, geometry, spinless, False) h_dual_basis_t = inverse_fourier_transform(h_dual_basis, grid, spinless) self.assertTrue( normal_ordered(h_dual_basis_t).isclose( normal_ordered(h_plane_wave)))
def test_fourier_transform(self): grid = Grid(dimensions=1, scale=1.5, length=3) spinless_set = [True, False] geometry = [('H', (0, )), ('H', (0.5, ))] for spinless in spinless_set: h_plane_wave = plane_wave_hamiltonian(grid, geometry, spinless, True) h_dual_basis = plane_wave_hamiltonian(grid, geometry, spinless, False) h_plane_wave_t = fourier_transform(h_plane_wave, grid, spinless) self.assertTrue( normal_ordered(h_plane_wave_t).isclose( normal_ordered(h_dual_basis)))
def test_jordan_wigner_dual_basis_hamiltonian(self): grid = Grid(dimensions=2, length=3, scale=1.) spinless = True geometry = [('H', (0, 0)), ('H', (0.5, 0.8))] fermion_hamiltonian = plane_wave_hamiltonian(grid, geometry, spinless, False, include_constant=True) qubit_hamiltonian = jordan_wigner(fermion_hamiltonian) test_hamiltonian = jordan_wigner_dual_basis_hamiltonian( grid, geometry, spinless, include_constant=True) self.assertTrue(test_hamiltonian.isclose(qubit_hamiltonian))
def test_plane_wave_hamiltonian_bad_element(self): grid = Grid(dimensions=3, scale=1.0, length=4) with self.assertRaises(ValueError): plane_wave_hamiltonian(grid, geometry=[('Unobtainium', (0, 0, 0))])
def test_plane_wave_hamiltonian_bad_geometry(self): grid = Grid(dimensions=1, scale=1.0, length=4) with self.assertRaises(ValueError): plane_wave_hamiltonian(grid, geometry=[('H', (0, 0, 0))])
def test_plane_wave_hamiltonian_default_to_jellium_with_no_geometry(self): grid = Grid(dimensions=1, scale=1.0, length=4) self.assertTrue( plane_wave_hamiltonian(grid).isclose(jellium_model(grid)))