コード例 #1
0
 def test_lih_rhf_bk(self):
     """ lih rhf bk test """
     driver = PySCFDriver(atom=self.lih,
                          unit=UnitsType.ANGSTROM,
                          charge=0,
                          spin=0,
                          basis='sto-3g',
                          hf_method=HFMethodType.RHF)
     result = self._run_driver(driver,
                               transformation=TransformationType.FULL,
                               qubit_mapping=QubitMappingType.BRAVYI_KITAEV)
     self._assert_energy_and_dipole(result, 'lih')
コード例 #2
0
 def test_zmatrix(self):
     """ Check z-matrix input """
     atom = 'H; H 1 1.0'
     driver = PySCFDriver(atom=atom,
                          unit=UnitsType.ANGSTROM,
                          charge=0,
                          spin=0,
                          basis='sto3g')
     molecule = driver.run()
     self.assertAlmostEqual(molecule.hf_energy,
                            -1.0661086493179366,
                            places=5)
コード例 #3
0
 def test_list_atom(self):
     """ Check input with list of strings """
     atom = ['H 0 0 0', 'H 0 0 1']
     driver = PySCFDriver(atom=atom,
                          unit=UnitsType.ANGSTROM,
                          charge=0,
                          spin=0,
                          basis='sto3g')
     molecule = driver.run()
     self.assertAlmostEqual(molecule.hf_energy,
                            -1.0661086493179366,
                            places=5)
コード例 #4
0
 def test_h3(self):
     """ Test for H3 chain, see also issue 1148 """
     atom = 'H 0 0 0; H 0 0 1; H 0 0 2'
     driver = PySCFDriver(atom=atom,
                          unit=UnitsType.ANGSTROM,
                          charge=0,
                          spin=1,
                          basis='sto3g')
     molecule = driver.run()
     self.assertAlmostEqual(molecule.hf_energy,
                            -1.523996200246108,
                            places=5)
コード例 #5
0
 def setUp(self):
     super().setUp()
     try:
         driver = PySCFDriver(atom='Li .0 .0 .0; H .0 .0 1.6',
                              unit=UnitsType.ANGSTROM,
                              charge=0,
                              spin=0,
                              basis='sto3g')
     except QiskitChemistryError:
         self.skipTest('PYSCF driver does not appear to be installed')
     self.qmolecule = driver.run()
     self.mp2info = MP2Info(self.qmolecule)
コード例 #6
0
    def setUp(self):
        super().setUp()
        try:
            self.molecule = "H 0.000000 0.000000 0.735000;H 0.000000 0.000000 0.000000"
            self.driver = PySCFDriver(atom=self.molecule,
                                      unit=UnitsType.ANGSTROM,
                                      charge=0,
                                      spin=0,
                                      basis='631g')
            self.qmolecule = self.driver.run()
            self.core = Hamiltonian(transformation=TransformationType.FULL,
                                    qubit_mapping=QubitMappingType.PARITY,
                                    two_qubit_reduction=True,
                                    freeze_core=True,
                                    orbital_reduction=[])
            self.qubit_op, _ = self.core.run(self.qmolecule)

            z2_symmetries = Z2Symmetries.find_Z2_symmetries(self.qubit_op)
            tapered_ops = z2_symmetries.taper(self.qubit_op)
            smallest_eig_value = 99999999999999
            smallest_idx = -1
            for idx, _ in enumerate(tapered_ops):
                ee = ExactEigensolver(tapered_ops[idx], k=1)
                curr_value = ee.run()['energy']
                if curr_value < smallest_eig_value:
                    smallest_eig_value = curr_value
                    smallest_idx = idx
            self.the_tapered_op = tapered_ops[smallest_idx]

            self.reference_energy_pUCCD = -1.1434447924298028
            self.reference_energy_UCCD0 = -1.1476045878481704
            self.reference_energy_UCCD0full = -1.1515491334334347
            # reference energy of UCCSD/VQE with tapering everywhere
            self.reference_energy_UCCSD = -1.1516142309717594
            # reference energy of UCCSD/VQE when no tapering on excitations is used
            self.reference_energy_UCCSD_no_tap_exc = -1.1516142309717594
            # excitations for succ
            self.reference_singlet_double_excitations = [[0, 1, 4, 5],
                                                         [0, 1, 4, 6],
                                                         [0, 1, 4, 7],
                                                         [0, 2, 4, 6],
                                                         [0, 2, 4, 7],
                                                         [0, 3, 4, 7]]
            # groups for succ_full
            self.reference_singlet_groups = [[[0, 1, 4, 5]],
                                             [[0, 1, 4, 6], [0, 2, 4, 5]],
                                             [[0, 1, 4, 7], [0, 3, 4, 5]],
                                             [[0, 2, 4, 6]],
                                             [[0, 2, 4, 7], [0, 3, 4, 6]],
                                             [[0, 3, 4, 7]]]
        except QiskitChemistryError:
            self.skipTest('PYSCF driver does not appear to be installed')
コード例 #7
0
    def setUp(self):
        try:
            driver = PySCFDriver(atom='Li .0 .0 .0; H .0 .0 1.595',
                                 unit=UnitsType.ANGSTROM,
                                 charge=0,
                                 spin=0,
                                 basis='sto3g')
        except QiskitChemistryError:
            self.skipTest('PYSCF driver does not appear to be installed')

        molecule = driver.run()
        self.fer_op = FermionicOperator(h1=molecule.one_body_integrals,
                                        h2=molecule.two_body_integrals)
コード例 #8
0
 def test_oh_uhf_parity(self):
     """ oh uhf parity test """
     driver = PySCFDriver(atom=self.o_h,
                          unit=UnitsType.ANGSTROM,
                          charge=0,
                          spin=1,
                          basis='sto-3g',
                          hf_method=HFMethodType.UHF)
     result = self._run_driver(driver,
                               transformation=TransformationType.FULL,
                               qubit_mapping=QubitMappingType.PARITY,
                               two_qubit_reduction=False)
     self._assert_energy_and_dipole(result, 'oh')
コード例 #9
0
 def test_lih_rhf_parity_2q(self):
     """ lih rhf parity 2q test """
     driver = PySCFDriver(atom=self.lih,
                          unit=UnitsType.ANGSTROM,
                          charge=0,
                          spin=0,
                          basis='sto-3g',
                          hf_method=HFMethodType.RHF)
     result = self._run_driver(driver,
                               transformation=TransformationType.FULL,
                               qubit_mapping=QubitMappingType.PARITY,
                               two_qubit_reduction=True)
     self._assert_energy_and_dipole(result, 'lih')
コード例 #10
0
ファイル: bo_chemistry.py プロジェクト: chris-n-self/qc_optim
def get_LiH_qubit_op(dist):
    """ 
    Use the qiskit chemistry package to get the qubit Hamiltonian for LiH

    Parameters
    ----------
    dist : float
        The nuclear separations

    Returns
    -------
    qubitOp : qiskit.aqua.operators.WeightedPauliOperator
        Qiskit representation of the qubit Hamiltonian
    shift : float
        The ground state of the qubit Hamiltonian needs to be corrected by this amount of
        energy to give the real physical energy. This includes the replusive energy between
        the nuclei and the energy shift of the frozen orbitals.
    """
    driver = PySCFDriver(
        atom="Li .0 .0 .0; H .0 .0 " + str(dist),
        unit=UnitsType.ANGSTROM,
        charge=0,
        spin=0,
        basis='sto3g',
    )
    molecule = driver.run()
    freeze_list = [0]
    remove_list = [-3, -2]
    repulsion_energy = molecule.nuclear_repulsion_energy
    num_particles = molecule.num_alpha + molecule.num_beta
    num_spin_orbitals = molecule.num_orbitals * 2
    remove_list = [x % molecule.num_orbitals for x in remove_list]
    freeze_list = [x % molecule.num_orbitals for x in freeze_list]
    remove_list = [x - len(freeze_list) for x in remove_list]
    remove_list += [
        x + molecule.num_orbitals - len(freeze_list) for x in remove_list
    ]
    freeze_list += [x + molecule.num_orbitals for x in freeze_list]
    ferOp = FermionicOperator(h1=molecule.one_body_integrals,
                              h2=molecule.two_body_integrals)
    ferOp, energy_shift = ferOp.fermion_mode_freezing(freeze_list)
    num_spin_orbitals -= len(freeze_list)
    num_particles -= len(freeze_list)
    ferOp = ferOp.fermion_mode_elimination(remove_list)
    num_spin_orbitals -= len(remove_list)
    qubitOp = ferOp.mapping(map_type='parity', threshold=1E-8)
    #qubitOp = qubitOp.two_qubit_reduced_operator(num_particles)
    qubitOp = Z2Symmetries.two_qubit_reduction(qubitOp, num_particles)
    shift = repulsion_energy + energy_shift

    return qubitOp, shift
コード例 #11
0
ファイル: test_adapt_vqe.py プロジェクト: v-r0/qiskit-aqua
    def setUp(self):
        super().setUp()

        try:
            self.driver = PySCFDriver(atom='H .0 .0 .0; H .0 .0 0.735',
                                      unit=UnitsType.ANGSTROM,
                                      basis='sto3g')
        except QiskitChemistryError:
            self.skipTest('PYSCF driver does not appear to be installed')
            return

        self.expected = -1.85727503

        self.transformation = FermionicTransformation()
コード例 #12
0
ファイル: test_logging.py プロジェクト: hushaohan/aqua
    def test_logging_emit(self):
        """ logging emit test """
        with self.assertLogs(QiskitLogDomains.DOMAIN_CHEMISTRY.value,
                             level='INFO') as log:
            try:
                driver = PySCFDriver(atom='H .0 .0 .0; H .0 .0 0.735',
                                     unit=UnitsType.ANGSTROM,
                                     basis='sto3g')
            except QiskitChemistryError:
                self.skipTest('PYSCF driver does not appear to be installed')
                return

            _ = driver.run()
            self.assertIn('PySCF', log.output[0])
コード例 #13
0
def get_uccsd_circuit(molecule, theta_vector=None, use_basis_gates=False):
    """Produce the full UCCSD circuit.
    Args:
    molecule :: string - must be a key of MOLECULE_TO_INFO
    theta_vector :: array - arguments for the vqe ansatz. If None, will generate random angles.
    use_basis_gates :: bool - Mike and Ike gates if False, Basis gates if True.
       
    Returns:
    circuit :: qiskit.QuantumCircuit - the UCCSD circuit parameterized
                                       by theta_vector, unoptimized
    """
    molecule_info = MOLECULE_TO_INFO[molecule]
    driver = PySCFDriver(atom=molecule_info.atomic_string, basis='sto3g')
    qmolecule = driver.run()
    hamiltonian = Hamiltonian(
        qubit_mapping=QubitMappingType.PARITY,
        two_qubit_reduction=True,
        freeze_core=True,
        orbital_reduction=molecule_info.orbital_reduction)

    energy_input = hamiltonian.run(qmolecule)
    qubit_op = energy_input.qubit_op
    num_spin_orbitals = hamiltonian.molecule_info['num_orbitals']
    num_particles = hamiltonian.molecule_info['num_particles']
    map_type = hamiltonian._qubit_mapping
    qubit_reduction = hamiltonian.molecule_info['two_qubit_reduction']

    HF_state = HartreeFock(qubit_op.num_qubits, num_spin_orbitals,
                           num_particles, map_type, qubit_reduction)
    var_form = UCCSD(qubit_op.num_qubits,
                     depth=1,
                     num_orbitals=num_spin_orbitals,
                     num_particles=num_particles,
                     active_occupied=molecule_info.active_occupied,
                     active_unoccupied=molecule_info.active_unoccupied,
                     initial_state=HF_state,
                     qubit_mapping=map_type,
                     two_qubit_reduction=qubit_reduction,
                     num_time_slices=1)

    if theta_vector is None:
        theta_vector = [
            np.random.rand() * 2 * np.pi
            for _ in range(var_form._num_parameters)
        ]

    circuit = var_form.construct_circuit(theta_vector,
                                         use_basis_gates=use_basis_gates)

    return circuit
コード例 #14
0
    def test_mgse_callback_vqe_uccsd_z2_nosymm(self):
        """ This time we reduce the operator so it has symmetries left. Whether z2 symmetry
            reduction is set to auto, or left turned off, the results should be same. We
            explicitly check the Z2 symmetry to ensure it empty and use classical solver
            to ensure the operators via the subsequent result computation are correct. """

        z2_symm = None

        def cb_create_solver(num_particles, num_orbitals, qubit_mapping,
                             two_qubit_reduction, z2_symmetries):

            nonlocal z2_symm
            z2_symm = z2_symmetries
            return NumPyMinimumEigensolver()

        driver = PySCFDriver(atom='Li .0 .0 -0.8; H .0 .0 0.8')
        warnings.filterwarnings('ignore', category=DeprecationWarning)
        mgse = MolecularGroundStateEnergy(
            driver,
            qubit_mapping=QubitMappingType.PARITY,
            two_qubit_reduction=True,
            freeze_core=True,
            orbital_reduction=[-3, -2],
            z2symmetry_reduction='auto')
        result = mgse.compute_energy(cb_create_solver)

        # Check a couple of values are as expected, energy for main operator and number of
        # particles and dipole from auxiliary operators.
        self.assertEqual(z2_symm.is_empty(), True)
        self.assertAlmostEqual(result.energy, -7.881, places=3)
        self.assertAlmostEqual(result.num_particles, 2)
        self.assertAlmostEqual(result.total_dipole_moment_in_debye,
                               4.667,
                               places=3)

        # Run with no symmetry reduction, which should match the prior result since there
        # are no symmetries to be found.
        mgse1 = MolecularGroundStateEnergy(
            driver,
            qubit_mapping=QubitMappingType.PARITY,
            two_qubit_reduction=True,
            freeze_core=True,
            orbital_reduction=[-3, -2])
        result1 = mgse1.compute_energy(cb_create_solver)

        self.assertEqual(z2_symm.is_empty(), True)
        self.assertEqual(str(result),
                         str(result1))  # Compare string form of results
        warnings.filterwarnings('always', category=DeprecationWarning)
コード例 #15
0
ファイル: vqe_H2.py プロジェクト: bzkarimi/VQE
def get_qubit_op(dist):
    driver = PySCFDriver(atom="H .0 .0 .0; H .0 .0 " + str(dist),
                         unit=UnitsType.ANGSTROM,
                         charge=0,
                         spin=0,
                         basis='sto3g')
    molecule = driver.run()
    nuc_energy = molecule.nuclear_repulsion_energy
    num_particles = molecule.num_alpha + molecule.num_beta
    num_spin_orbitals = molecule.num_orbitals * 2
    ferOp = FermionicOperator(h1=molecule.one_body_integrals,
                              h2=molecule.two_body_integrals)
    qubitOp = ferOp.mapping(map_type='parity', threshold=0.00000001)
    qubitOp = Z2Symmetries.two_qubit_reduction(qubitOp, num_particles)
    return qubitOp, num_particles, num_spin_orbitals, nuc_energy
コード例 #16
0
def JW_H(systemData={'driver_string': 'Li 0.0 0.0 0.0; H 0.0 0.0 1.548', 'basis': 'sto3g'}):
                            
    driver = PySCFDriver(   atom=systemData["atomstring"],
                            basis=systemData["basis"]       )

    mol = driver.run()
    OB = mol.one_body_integrals
    TB = mol.two_body_integrals

    FerOp = FermionicOperator(OB, TB)
    mapping = FerOp.mapping('jordan_wigner')
    weights = [w[0] for w in mapping.paulis]
    operators = [w[1].to_label() for w in mapping.paulis]

    return nk.operator.PauliStrings(operators, weights)
コード例 #17
0
    def setUp(self):
        super().setUp()
        try:
            self.driver = PySCFDriver(atom='H .0 .0 .0; H .0 .0 0.735',
                                      unit=UnitsType.ANGSTROM,
                                      charge=0,
                                      spin=0,
                                      basis='sto3g')
        except QiskitChemistryError:
            self.skipTest('PYSCF driver does not appear to be installed')

        self.reference_energy = -1.137306

        self.transformation = FermionicTransformation(
            qubit_mapping=QubitMappingType.JORDAN_WIGNER)
コード例 #18
0
    def test_mp2_h2(self):
        """ Just one double excitation expected - see issue 1151 """
        driver = PySCFDriver(atom="H 0 0 0; H 0 0 0.7",
                             unit=UnitsType.ANGSTROM,
                             charge=0,
                             spin=0,
                             basis='sto3g')
        molecule = driver.run()

        mp2info = MP2Info(molecule)
        terms = mp2info.mp2_terms()
        self.assertEqual(1, len(terms.keys()))
        np.testing.assert_array_almost_equal(
            [-0.06834019757197064, -0.012232934733533095],
            terms['0_1_2_3'],
            decimal=6)
コード例 #19
0
def createPlot1(bondLengthMin=0.5,
                bondLengthMax=1.5,
                numberOfPoints=10,
                initialParameters=None,
                numberOfParameters=16,
                shotsPerPoint=1000,
                registerSize=12,
                map_type='jordan_wigner'):
    if initialParameters is None:
        initialParameters = np.random.rand(numberOfParameters)
    global qubitOp
    global qr_size
    global shots
    shots = shotsPerPoint
    qr_size = registerSize
    optimizer = COBYLA(maxiter=20)
    bondLengths = []
    values = []
    delta = (bondLengthMax - bondLengthMin) / numberOfPoints
    for i in range(numberOfPoints):
        bondLengths.append(bondLengthMin + i * delta)
    for bondLength in bondLengths:
        driver = PySCFDriver(atom="H .0 .0 .0; H .0 .0 " + str(bondLength),
                             unit=UnitsType.ANGSTROM,
                             charge=0,
                             spin=0,
                             basis='sto3g')
        molecule = driver.run()
        repulsion_energy = molecule.nuclear_repulsion_energy
        num_spin_orbitals = molecule.num_orbitals * 2
        num_particles = molecule.num_alpha + molecule.num_beta
        ferOp = FermionicOperator(h1=molecule.one_body_integrals,
                                  h2=molecule.two_body_integrals)
        qubitOp = ferOp.mapping(map_type=map_type, threshold=0.00000001)
        sol_opt = optimizer.optimize(numberOfParameters,
                                     energy_opt,
                                     gradient_function=None,
                                     variable_bounds=None,
                                     initial_point=initialParameters)
        values.append(sol_opt[1] + repulsion_energy)
    filename = 'Energy - BondLengths'
    with open(filename, 'wb') as f:
        pickle.dump([bondLengths, values], f)
    plt.plot(bondLengths, values)
    plt.ylabel('Ground State Energy')
    plt.xlabel('Bond Length')
    plt.show()
コード例 #20
0
    def run(self, instance, verbose=False):
        for i, d in enumerate(self.distances):
            print("Simulation step", i, "simulating molecule: ", self.molecule.format(d))
            if verbose:
                print("PySCFDriver")
            driver = PySCFDriver(self.molecule.format(d), basis="sto3g")
            if verbose:
                print("driver.run")
            qmolecule = driver.run()
            if verbose:
                print("Hamiltonian")
            operator = Hamiltonian(qubit_mapping=QubitMappingType.PARITY, 
                                   two_qubit_reduction=self.two_qubit_reduction, 
                                   freeze_core=self.freeze_core, 
                                   orbital_reduction=self.orbital_reduction)
            if verbose:
                print("Hamiltonian.run")
            qubit_op, aux_ops = operator.run(qmolecule)
            if verbose:
                print("SLSQP")
            optimizer = SLSQP(maxiter=100)
            
            if verbose:
                print("HartreeFock")
            initial_state = HartreeFock(operator.molecule_info["num_orbitals"], 
                                        operator.molecule_info["num_particles"], 
                                        "parity", 
                                        two_qubit_reduction=self.two_qubit_reduction)
            if verbose:
                print("UCCSD")
            var_form = UCCSD(num_orbitals=operator.molecule_info["num_orbitals"], 
                             num_particles=operator.molecule_info["num_particles"], 
                             initial_state=initial_state, 
                             qubit_mapping="parity", 
                             two_qubit_reduction=self.two_qubit_reduction)
            if verbose:
                print("VQE")
            algo = VQE(qubit_op, var_form, optimizer, aux_operators=aux_ops)
            if verbose:
                print("VQE.run")
            vqe_result = algo.run(instance)
            if verbose:
                print("Hamiltonian.process_algorithm_result")
            vqe_result_processed = operator.process_algorithm_result(vqe_result)

            self.vqe_energies.append(vqe_result_processed.energy)
            self.hf_energies.append(vqe_result_processed.hartree_fock_energy)
コード例 #21
0
 def setUp(self):
     """Setup."""
     super().setUp()
     aqua_globals.random_seed = 0
     atom = 'H .0 .0 .7414; H .0 .0 .0'
     pyscf_driver = PySCFDriver(atom=atom,
                                unit=UnitsType.ANGSTROM, charge=0, spin=0, basis='sto3g')
     self.molecule = pyscf_driver.run()
     core = Hamiltonian(transformation=TransformationType.FULL,
                        qubit_mapping=QubitMappingType.PARITY,
                        two_qubit_reduction=True,
                        freeze_core=False,
                        orbital_reduction=[])
     qubit_op, _ = core.run(self.molecule)
     exact_eigensolver = ExactEigensolver(qubit_op, k=2 ** qubit_op.num_qubits)
     result = exact_eigensolver.run()
     self.reference = result['eigvals'].real
コード例 #22
0
ファイル: test_app_mgse.py プロジェクト: dongreenberg/aqua
    def setUp(self):
        super().setUp()
        try:
            self.driver = PySCFDriver(atom='H .0 .0 .0; H .0 .0 0.735',
                                      unit=UnitsType.ANGSTROM,
                                      charge=0,
                                      spin=0,
                                      basis='sto3g')
        except QiskitChemistryError:
            self.skipTest('PYSCF driver does not appear to be installed')

        self.npme = NumPyMinimumEigensolver()

        self.vqe = VQE(var_form=TwoLocal(rotation_blocks='ry', entanglement_blocks='cz'))
        self.vqe.set_backend(BasicAer.get_backend('statevector_simulator'))

        self.reference_energy = -1.137306
コード例 #23
0
def load_qubitop_for_molecule(molecule_data):
    atom_list = [a[0] + ' ' + " ".join([str(elem) for elem in a[1]]) for a in molecule_data['geometry']]
    atom = "; ".join(atom_list) 
    #atom = 'Li .0 .0 .0; H .0 .0 3.9'
    basis = molecule_data['basis']
    transform = molecule_data['transform']
    electrons = molecule_data['electrons']
    active = molecule_data['active_orbitals']
    driver = PySCFDriver(atom=atom, unit=UnitsType.ANGSTROM, basis=basis, charge=0, spin=0)
    molecule = driver.run()
    num_particles = molecule.num_alpha + molecule.num_beta
    num_spin_orbitals = molecule.num_orbitals * 2
    #print("# of electrons: {}".format(num_particles))
    #print("# of spin orbitals: {}".format(num_spin_orbitals))
    freeze_list = [x for x in range(int(active/2), int(num_particles/2))]
    remove_list = [-x for x in range(active,molecule.num_orbitals-int(num_particles/2)+int(active/2))]
    #print(freeze_list)
    #print(remove_list)

    if transform == 'BK':
        map_type = 'bravyi_kitaev'
    elif transform == 'JW':
        map_type = 'jordan_wigner'
    else:
        map_type = 'parity'
    remove_list = [x % molecule.num_orbitals for x in remove_list]
    freeze_list = [x % molecule.num_orbitals for x in freeze_list]
    remove_list = [x - len(freeze_list) for x in remove_list]
    remove_list += [x + molecule.num_orbitals - len(freeze_list)  for x in remove_list]
    freeze_list += [x + molecule.num_orbitals for x in freeze_list]
    fermiOp = FermionicOperator(h1=molecule.one_body_integrals, h2=molecule.two_body_integrals)
    energy_shift = 0
    if len(freeze_list) > 0:
        fermiOp, energy_shift = fermiOp.fermion_mode_freezing(freeze_list)
    num_spin_orbitals -= len(freeze_list)
    num_particles -= len(freeze_list)
    if len(remove_list) > 0:
        fermiOp = fermiOp.fermion_mode_elimination(remove_list)
    num_spin_orbitals -= len(remove_list)
    qubitOp = fermiOp.mapping(map_type=map_type, threshold=0.00000001)
    if len(freeze_list) > 0 or len(remove_list) >0:
        qubitOp = Z2Symmetries.two_qubit_reduction(qubitOp, num_particles)

    #print(qubitOp.print_operators())
    num_spin_orbitals= qubitOp.num_qubits
    return molecule, qubitOp, map_type, num_particles, num_spin_orbitals
コード例 #24
0
    def setUp(self):
        super().setUp()
        try:
            # pylint: disable=import-outside-toplevel
            from qiskit.chemistry.drivers import PySCFDriver
            PySCFDriver(atom='Li .0 .0 .0; H .0 .0 1.6')
        except QiskitChemistryError:
            self.skipTest('PYSCF driver does not appear to be installed')

        try:
            # pylint: disable=import-outside-toplevel
            # pylint: disable=unused-import
            from qiskit import Aer
        except Exception as ex:  # pylint: disable=broad-except
            self.skipTest(
                "Aer doesn't appear to be installed. Error: '{}'".format(
                    str(ex)))
            return
コード例 #25
0
    def setUp(self):
        try:
            driver = PySCFDriver(atom='Li .0 .0 .0; H .0 .0 1.6',
                                 unit=UnitsType.ANGSTROM,
                                 charge=0,
                                 spin=0,
                                 basis='sto3g')
        except QiskitChemistryError:
            self.skipTest('PYSCF driver does not appear to be installed')
        self.qmolecule = driver.run()
        self.core = Hamiltonian(transformation=TransformationType.FULL,
                                qubit_mapping=QubitMappingType.PARITY,
                                two_qubit_reduction=True,
                                freeze_core=True,
                                orbital_reduction=[])
        self.qubit_op, _ = self.core.run(self.qmolecule)
        self.symmetries, self.sq_paulis, self.cliffords, self.sq_list = self.qubit_op.find_Z2_symmetries()

        self.reference_energy = -7.882096489442
コード例 #26
0
def h2(dist=0.75):
    mol = PySCFDriver(atom=
                      'H 0.0 0.0 0.0;'\
                      'H 0.0 0.0 {}'.format(dist), unit=UnitsType.ANGSTROM, charge=0,
                      spin=0, basis='sto-3g')
    mol = mol.run()
    h1 = mol.one_body_integrals
    h2 = mol.two_body_integrals

    nuclear_repulsion_energy = mol.nuclear_repulsion_energy
    num_particles = mol.num_alpha + mol.num_beta + 0
    ferOp = FermionicOperator(h1=h1, h2=h2)
    qubitOp = ferOp.mapping(map_type='parity', threshold=0.00000001)
    qubitOp = Z2Symmetries.two_qubit_reduction(qubitOp, num_particles)

    cHam = op_converter.to_matrix_operator(qubitOp)
    cHam = cHam.dense_matrix + nuclear_repulsion_energy * numpy.identity(4)

    return cHam
コード例 #27
0
    def test_particle_hole(self,
                           atom,
                           charge=0,
                           spin=0,
                           basis='sto3g',
                           hf_method=HFMethodType.RHF):
        """ particle hole test """
        try:
            driver = PySCFDriver(atom=atom,
                                 unit=UnitsType.ANGSTROM,
                                 charge=charge,
                                 spin=spin,
                                 basis=basis,
                                 hf_method=hf_method)
        except QiskitChemistryError:
            self.skipTest('PYSCF driver does not appear to be installed')

        config = '{}, charge={}, spin={}, basis={}, {}'.format(
            atom, charge, spin, basis, hf_method.value)

        molecule = driver.run()
        fer_op = FermionicOperator(h1=molecule.one_body_integrals,
                                   h2=molecule.two_body_integrals)

        ph_fer_op, ph_shift = fer_op.particle_hole_transformation(
            [molecule.num_alpha, molecule.num_beta])

        # ph_shift should be the electronic part of the hartree fock energy
        self.assertAlmostEqual(-ph_shift,
                               molecule.hf_energy -
                               molecule.nuclear_repulsion_energy,
                               msg=config)

        # Energy in original fer_op should same as ph transformed one added with ph_shift
        jw_op = fer_op.mapping('jordan_wigner')
        result = NumPyMinimumEigensolver(jw_op).run()

        ph_jw_op = ph_fer_op.mapping('jordan_wigner')
        ph_result = NumPyMinimumEigensolver(ph_jw_op).run()

        self.assertAlmostEqual(result.eigenvalue.real,
                               ph_result.eigenvalue.real - ph_shift,
                               msg=config)
コード例 #28
0
ファイル: test_qeom_ee.py プロジェクト: hushaohan/aqua
 def setUp(self):
     """Setup."""
     super().setUp()
     try:
         atom = 'H .0 .0 .7414; H .0 .0 .0'
         pyscf_driver = PySCFDriver(atom=atom,
                                    unit=UnitsType.ANGSTROM, charge=0, spin=0, basis='sto3g')
         self.molecule = pyscf_driver.run()
         core = Hamiltonian(transformation=TransformationType.FULL,
                            qubit_mapping=QubitMappingType.PARITY,
                            two_qubit_reduction=True,
                            freeze_core=False,
                            orbital_reduction=[])
         qubit_op, _ = core.run(self.molecule)
         exact_eigensolver = NumPyEigensolver(qubit_op, k=2 ** qubit_op.num_qubits)
         result = exact_eigensolver.run()
         self.reference = result.eigenvalues.real
     except QiskitChemistryError:
         self.skipTest('PYSCF driver does not appear to be installed')
コード例 #29
0
    def setUp(self):
        super().setUp()
        aqua_globals.random_seed = 8
        try:
            self.driver = PySCFDriver(atom='H .0 .0 .0; H .0 .0 0.75',
                                      unit=UnitsType.ANGSTROM,
                                      charge=0,
                                      spin=0,
                                      basis='sto3g')
        except QiskitChemistryError:
            self.skipTest('PYSCF driver does not appear to be installed')

        self.reference_energies = [-1.8427016, -1.8427016 + 0.5943372, -1.8427016 + 0.95788352,
                                   -1.8427016 + 1.5969296]
        self.transformation = \
            FermionicTransformation(qubit_mapping=FermionicQubitMappingType.JORDAN_WIGNER)
        solver = NumPyEigensolver()
        self.ref = solver
        self.quantum_instance = QuantumInstance(BasicAer.get_backend('statevector_simulator'),
                                                seed_transpiler=90, seed_simulator=12)
コード例 #30
0
    def setUp(self):
        super().setUp()
        try:
            self.molecule = "H 0.000000 0.000000 0.735000;H 0.000000 0.000000 0.000000"
            self.driver = PySCFDriver(atom=self.molecule,
                                      unit=UnitsType.ANGSTROM,
                                      charge=0,
                                      spin=0,
                                      basis='631g')
            self.fermionic_transformation = \
                FermionicTransformation(transformation=TransformationType.FULL,
                                        qubit_mapping=QubitMappingType.PARITY,
                                        two_qubit_reduction=True,
                                        freeze_core=True,
                                        orbital_reduction=[])
            self.qubit_op, _ = self.fermionic_transformation.transform(
                self.driver)

            self.reference_energy_pUCCD = -1.1434447924298028
            self.reference_energy_UCCD0 = -1.1476045878481704
            self.reference_energy_UCCD0full = -1.1515491334334347
            # reference energy of UCCSD/VQE with tapering everywhere
            self.reference_energy_UCCSD = -1.1516142309717594
            # reference energy of UCCSD/VQE when no tapering on excitations is used
            self.reference_energy_UCCSD_no_tap_exc = -1.1516142309717594
            # excitations for succ
            self.reference_singlet_double_excitations = [[0, 1, 4, 5],
                                                         [0, 1, 4, 6],
                                                         [0, 1, 4, 7],
                                                         [0, 2, 4, 6],
                                                         [0, 2, 4, 7],
                                                         [0, 3, 4, 7]]
            # groups for succ_full
            self.reference_singlet_groups = [[[0, 1, 4, 5]],
                                             [[0, 1, 4, 6], [0, 2, 4, 5]],
                                             [[0, 1, 4, 7], [0, 3, 4, 5]],
                                             [[0, 2, 4, 6]],
                                             [[0, 2, 4, 7], [0, 3, 4, 6]],
                                             [[0, 3, 4, 7]]]
        except QiskitChemistryError:
            self.skipTest('PYSCF driver does not appear to be installed')