Ejemplo n.º 1
0
    def test_orbnum_reduce_symmetry_qubits(self):
        # Generate the fermionic Hamiltonians,
        # number of orbitals and number of electrons.
        lih_sto_hamil, lih_sto_numorb, lih_sto_numel = LiH_sto3g()

        # Use test function to reduce the qubits.
        lih_sto_qbt = (symmetry_conserving_bravyi_kitaev(
            lih_sto_hamil, lih_sto_numorb, lih_sto_numel))

        self.assertEqual(number_of_qubits(lih_sto_qbt, lih_sto_numorb),
                         lih_sto_numorb - 2)
 def test_single_operator(self):
     # Dummy operator acting only on 2 qubits of overall 4-qubit system
     op = FermionOperator("0^ 1^ 1 0") + FermionOperator("1^ 0^ 0 1")
     trafo_op = symmetry_conserving_bravyi_kitaev(op,
                                                  active_fermions=2,
                                                  active_orbitals=4)
     # Check via eigenspectrum -- needs to stay the same
     e_op = eigenspectrum(op)
     e_trafo = eigenspectrum(trafo_op)
     # Check eigenvalues
     self.assertSequenceEqual(e_op.tolist(), e_trafo.tolist())
Ejemplo n.º 3
0
    def test_energy_reduce_symmetry_qubits(self):
        # Generate the fermionic Hamiltonians,
        # number of orbitals and number of electrons.
        lih_sto_hamil, lih_sto_numorb, lih_sto_numel = LiH_sto3g()

        # Use test function to reduce the qubits.
        lih_sto_qbt = (symmetry_conserving_bravyi_kitaev(
            lih_sto_hamil, lih_sto_numorb, lih_sto_numel))

        self.assertAlmostEqual(
            eigenspectrum(lih_sto_qbt)[0],
            eigenspectrum(lih_sto_hamil)[0])
Ejemplo n.º 4
0
    def test_hubbard_reduce_symmetry_qubits(self):
        for i in range(4):
            n_sites = i + 2
            n_ferm = n_sites
            hub_hamil, n_orb = set_1D_hubbard(n_sites)

            # Use test function to reduce the qubits.
            hub_qbt = (symmetry_conserving_bravyi_kitaev(
                hub_hamil, n_orb, n_ferm))

            sparse_op = get_sparse_operator(hub_hamil)
            ground_energy, _ = jw_get_ground_state_at_particle_number(
                sparse_op, n_ferm)

            self.assertAlmostEqual(eigenspectrum(hub_qbt)[0], ground_energy)
Ejemplo n.º 5
0
    def test_errors_reduce_symmetry_qubits(self):
        # Generate the fermionic Hamiltonians,
        # number of orbitals and number of electrons.
        lih_sto_hamil, lih_sto_numorb, lih_sto_numel = LiH_sto3g()

        with self.assertRaises(ValueError):
            symmetry_conserving_bravyi_kitaev(0, lih_sto_numorb, lih_sto_numel)
        with self.assertRaises(ValueError):
            symmetry_conserving_bravyi_kitaev(lih_sto_hamil, 1.5, lih_sto_numel)
        with self.assertRaises(ValueError):
            symmetry_conserving_bravyi_kitaev(lih_sto_hamil, lih_sto_numorb,
                                              3.6)