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.assertEqual(normal_ordered(h_dual_basis_t),
                      normal_ordered(h_plane_wave))
Example #2
0
 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) ==
             normal_ordered(h_dual_basis))
 def test_inverse_fourier_transform_1d(self):
     grid = Grid(dimensions=1, scale=1.5, length=4)
     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_dual_basis_t = inverse_fourier_transform(h_dual_basis, grid,
                                                    spinless)
         self.assertEqual(normal_ordered(h_dual_basis_t),
                          normal_ordered(h_plane_wave))
    def test_fourier_transform(self):
        for length in [2, 3]:
            grid = Grid(dimensions=1, scale=1.5, length=length)
            spinless_set = [True, False]
            geometry = [('H', (0.1,)), ('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.assertEqual(normal_ordered(h_plane_wave_t),
                                 normal_ordered(h_dual_basis))

                # Verify that all 3 are Hermitian
                plane_wave_operator = get_sparse_operator(h_plane_wave)
                dual_operator = get_sparse_operator(h_dual_basis)
                plane_wave_t_operator = get_sparse_operator(h_plane_wave_t)
                self.assertTrue(is_hermitian(plane_wave_operator))
                self.assertTrue(is_hermitian(dual_operator))
                self.assertTrue(is_hermitian(plane_wave_t_operator))
Example #5
0
def dual_basis_hamiltonian(n_dimensions,
                           system_size,
                           plane_wave=False,
                           spinless=True):
    """Return the plane wave dual basis hamiltonian with the given parameters.

    Returns: the Hamiltonian as a normal-ordered FermionOperator.

    Args:
        n_dimensions (int): The number of dimensions in the system.
        system_size (int): The side length along each dimension.
        plane_wave (bool): Whether the system is in the plane wave basis.
        spinless (bool): Whether the system is spinless.

    Notes:
        Follows Eq. 10 of https://arxiv.org/pdf/1706.00023.pdf.
    """
    grid = Grid(n_dimensions, length=system_size, scale=1.0 * system_size)
    hamiltonian = plane_wave_hamiltonian(grid,
                                         spinless=spinless,
                                         plane_wave=plane_wave)
    return normal_ordered(hamiltonian)
Example #6
0
    def __init__(self, a=7.72, n=3, n_active_el=2, n_active_orb=4):
        self.a = a
        self.n = n
        self.n_active_el = n_active_el
        self.n_active_orb = n_active_orb
        self.N_units = 4
        self.opt_energy = None
        self.opt_amplitudes = None

        species_a = 'H'
        species_b = 'Li'

        # Construct a fermion Hamiltonian
        grid = Grid(3, self.n, self.a)
        geometry = [(species_a, (0, 0, 0)), (species_a, (0, 0.5, 0.5)),
                    (species_a, (0.5, 0, 0.5)), (species_a, (0.5, 0.5, 0)),
                    (species_b, (0.5, 0.5, 0.5)), (species_b, (0.5, 0, 0)),
                    (species_b, (0, 0.5, 0)), (species_b, (0, 0, 0.5))]
        self.fermion_hamiltonian = plane_wave_hamiltonian(
            grid,
            geometry=geometry,
            spinless=False,
            plane_wave=False,
            include_constant=False,
            e_cutoff=None)

        # Freeze specified orbitals
        n_qubits = 2 * n * n * n
        n_electrons = 4 * 3 + 4 * 1

        # Determine the indices of occupied orbitals to be frozen
        if self.n == 3:
            to_fill = ((1, 1, 1), (0, 1, 1), (2, 1, 1), (1, 0, 1), (1, 2, 1),
                       (1, 1, 0), (1, 1, 2), (0, 0, 1))
        else:
            to_fill = range(n_electrons - self.n_active_el)
        to_fill_ids = []
        for s in to_fill:
            to_fill_ids.append(orbital_id(grid, s, 0))
            to_fill_ids.append(orbital_id(grid, s, 1))
        to_fill_ids = to_fill_ids[0:(n_electrons - self.n_active_el)]
        #print(to_fill_ids)
        #print('# of terms: {}'.format(len(self.fermion_hamiltonian.terms)))
        self.fermion_hamiltonian = freeze_orbitals(self.fermion_hamiltonian,
                                                   to_fill_ids)
        #print('# of terms: {}'.format(len(self.fermion_hamiltonian.terms)))

        # Freeze unoccupied orbitals
        to_freeze_ids = range(self.n_active_orb,
                              n_qubits - (n_electrons - self.n_active_el))
        #print(to_freeze_ids)
        self.fermion_hamiltonian = freeze_orbitals(self.fermion_hamiltonian,
                                                   [], to_freeze_ids)

        print('# of terms: {}'.format(len(self.fermion_hamiltonian.terms)))

        # Construct qubit Hamiltonian
        self.qubit_hamiltonian = jordan_wigner(self.fermion_hamiltonian)

        # Initialize com;iler engine
        self.compiler_engine = uccsd_trotter_engine()