コード例 #1
0
    def setUp(self):
        super().setUp()

        self.driver1 = HDF5Driver(
            hdf5_input=self.get_resource_path('test_oovqe_h4.hdf5'))
        self.driver2 = HDF5Driver(
            hdf5_input=self.get_resource_path('test_oovqe_lih.hdf5'))
        self.driver3 = HDF5Driver(
            hdf5_input=self.get_resource_path('test_oovqe_h4_uhf.hdf5'))

        self.energy1_rotation = -3.0104
        self.energy1 = -2.77  # energy of the VQE with pUCCD ansatz and LBFGSB optimizer
        self.energy2 = -7.70
        self.energy3 = -2.50
        self.initial_point1 = [
            0.039374, -0.47225463, -0.61891996, 0.02598386, 0.79045546,
            -0.04134567, 0.04944946, -0.02971617, -0.00374005, 0.77542149
        ]

        self.seed = 50

        self.optimizer = COBYLA(maxiter=1)
        self.transformation1 = \
            FermionicTransformation(qubit_mapping=FermionicQubitMappingType.JORDAN_WIGNER,
                                    two_qubit_reduction=False)
        self.transformation2 = \
            FermionicTransformation(qubit_mapping=FermionicQubitMappingType.JORDAN_WIGNER,
                                    two_qubit_reduction=False,
                                    freeze_core=True)

        self.quantum_instance = QuantumInstance(
            BasicAer.get_backend('statevector_simulator'),
            shots=1,
            seed_simulator=self.seed,
            seed_transpiler=self.seed)
コード例 #2
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')
コード例 #3
0
    def setUp(self):
        super().setUp()
        self.reference_energy = -1.1373060356951838

        self.seed = 700
        aqua_globals.random_seed = self.seed

        self.driver = HDF5Driver(
            self.get_resource_path('test_driver_hdf5.hdf5'))
        fermionic_transformation = FermionicTransformation(
            qubit_mapping=QubitMappingType.PARITY, two_qubit_reduction=False)

        self.qubit_op, _ = fermionic_transformation.transform(self.driver)
        self.fermionic_transformation = fermionic_transformation

        self.optimizer = SLSQP(maxiter=100)
        initial_state = HartreeFock(
            fermionic_transformation.molecule_info['num_orbitals'],
            fermionic_transformation.molecule_info['num_particles'],
            qubit_mapping=fermionic_transformation._qubit_mapping,
            two_qubit_reduction=fermionic_transformation._two_qubit_reduction)
        self.var_form = UCCSD(
            num_orbitals=fermionic_transformation.
            molecule_info['num_orbitals'],
            num_particles=fermionic_transformation.
            molecule_info['num_particles'],
            initial_state=initial_state,
            qubit_mapping=fermionic_transformation._qubit_mapping,
            two_qubit_reduction=fermionic_transformation._two_qubit_reduction)
コード例 #4
0
    def test_hf_value(self, mapping):
        """ hf value test """
        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')

        fermionic_transformation = FermionicTransformation(transformation=TransformationType.FULL,
                                                           qubit_mapping=mapping,
                                                           two_qubit_reduction=False,
                                                           freeze_core=False,
                                                           orbital_reduction=[])

        qubit_op, _ = fermionic_transformation.transform(driver)

        hrfo = HartreeFock(fermionic_transformation.molecule_info['num_orbitals'],
                           fermionic_transformation.molecule_info['num_particles'],
                           mapping.value,
                           two_qubit_reduction=False)
        qc = hrfo.construct_circuit('vector')
        exp = ~StateFn(qubit_op) @ StateFn(qc)
        hf_energy = exp.eval().real \
            + fermionic_transformation._nuclear_repulsion_energy

        self.assertAlmostEqual(fermionic_transformation._hf_energy, hf_energy, places=6)
コード例 #5
0
ファイル: test_symmetries.py プロジェクト: dongreenberg/aqua
    def setUp(self):
        super().setUp()
        try:
            self.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.fermionic_transformation = FermionicTransformation(
            transformation=TransformationType.FULL,
            qubit_mapping=QubitMappingType.PARITY,
            two_qubit_reduction=True,
            freeze_core=True,
            orbital_reduction=[],
            z2symmetry_reduction='auto')

        self.qubit_op, _ = self.fermionic_transformation.transform(self.driver)

        self.z2_symmetries = self.fermionic_transformation.molecule_info.pop(
            'z2_symmetries')

        self.reference_energy = -7.882096489442
コード例 #6
0
    def test_excitation_preserving(self):
        """Test the excitation preserving wavefunction on a chemistry example."""

        driver = HDF5Driver(self.get_resource_path('test_driver_hdf5.hdf5'))
        fermionic_transformation = FermionicTransformation(
            qubit_mapping=QubitMappingType.PARITY, two_qubit_reduction=False)

        qubit_op, _ = fermionic_transformation.transform(driver)

        optimizer = SLSQP(maxiter=100)
        initial_state = HartreeFock(
            fermionic_transformation.molecule_info['num_orbitals'],
            fermionic_transformation.molecule_info['num_particles'],
            qubit_mapping=fermionic_transformation._qubit_mapping,
            two_qubit_reduction=fermionic_transformation._two_qubit_reduction)

        wavefunction = ExcitationPreserving(qubit_op.num_qubits,
                                            initial_state=initial_state)

        solver = VQE(var_form=wavefunction,
                     optimizer=optimizer,
                     quantum_instance=QuantumInstance(
                         BasicAer.get_backend('statevector_simulator'),
                         seed_simulator=aqua_globals.random_seed,
                         seed_transpiler=aqua_globals.random_seed))

        gsc = GroundStateEigensolver(fermionic_transformation, solver)

        result = gsc.solve(driver)

        self.assertAlmostEqual(result.energy, self.reference_energy, places=4)
コード例 #7
0
    def test_orbital_reduction(self):
        """ orbital reduction test --- Remove virtual orbital just
            for test purposes (not sensible!)
        """
        fermionic_transformation = FermionicTransformation(
            transformation=TransformationType.FULL,
            qubit_mapping=QubitMappingType.JORDAN_WIGNER,
            two_qubit_reduction=False,
            freeze_core=False,
            orbital_reduction=[-1])

        # get dummy aux operator
        qmolecule = self.driver.run()
        fer_op = FermionicOperator(h1=qmolecule.one_body_integrals,
                                   h2=qmolecule.two_body_integrals)
        dummy = fer_op.total_particle_number()
        expected = (I ^ I) - 0.5 * (I ^ Z) - 0.5 * (Z ^ I)

        qubit_op, aux_ops = fermionic_transformation.transform(
            self.driver, [dummy])
        self._validate_vars(fermionic_transformation)
        self._validate_info(fermionic_transformation, num_orbitals=2)
        self._validate_input_object(qubit_op, num_qubits=2, num_paulis=4)

        # the first six aux_ops are added automatically, ours is the 7th one
        self.assertEqual(aux_ops[6], expected)
コード例 #8
0
    def test_uccsd_hf_qUCCSD(self):
        """ uccsd tapering test using all double excitations """

        fermionic_transformation = FermionicTransformation(
            transformation=TransformationType.FULL,
            qubit_mapping=QubitMappingType.PARITY,
            two_qubit_reduction=True,
            freeze_core=True,
            orbital_reduction=[],
            z2symmetry_reduction='auto')

        qubit_op, _ = fermionic_transformation.transform(self.driver)

        # optimizer
        optimizer = SLSQP(maxiter=100)

        # initial state
        init_state = HartreeFock(
            num_orbitals=fermionic_transformation.
            molecule_info['num_orbitals'],
            qubit_mapping=fermionic_transformation._qubit_mapping,
            two_qubit_reduction=fermionic_transformation._two_qubit_reduction,
            num_particles=fermionic_transformation.
            molecule_info['num_particles'],
            sq_list=fermionic_transformation.molecule_info['z2_symmetries'].
            sq_list)

        var_form = UCCSD(
            num_orbitals=fermionic_transformation.
            molecule_info['num_orbitals'],
            num_particles=fermionic_transformation.
            molecule_info['num_particles'],
            active_occupied=None,
            active_unoccupied=None,
            initial_state=init_state,
            qubit_mapping=fermionic_transformation._qubit_mapping,
            two_qubit_reduction=fermionic_transformation._two_qubit_reduction,
            num_time_slices=1,
            z2_symmetries=fermionic_transformation.
            molecule_info['z2_symmetries'],
            shallow_circuit_concat=False,
            method_doubles='ucc',
            excitation_type='sd',
            skip_commute_test=True)

        solver = VQE(
            var_form=var_form,
            optimizer=optimizer,
            quantum_instance=QuantumInstance(
                backend=BasicAer.get_backend('statevector_simulator')))

        raw_result = solver.compute_minimum_eigenvalue(qubit_op, None)
        result = fermionic_transformation.interpret(raw_result)

        self.assertAlmostEqual(result.energy,
                               self.reference_energy_UCCSD,
                               places=6)
コード例 #9
0
    def test_freeze_core(self):
        """ freeze core test -- Should be in effect a no-op for H2 """
        fermionic_transformation = FermionicTransformation(
            transformation=TransformationType.FULL,
            qubit_mapping=QubitMappingType.JORDAN_WIGNER,
            two_qubit_reduction=False,
            freeze_core=True,
            orbital_reduction=[])

        qubit_op, _ = fermionic_transformation.transform(self.driver)
        self._validate_vars(fermionic_transformation)
        self._validate_info(fermionic_transformation)
        self._validate_input_object(qubit_op)
コード例 #10
0
    def test_particle_hole(self):
        """ particle hole test """
        fermionic_transformation = FermionicTransformation(
            transformation=TransformationType.PARTICLE_HOLE,
            qubit_mapping=QubitMappingType.JORDAN_WIGNER,
            two_qubit_reduction=False,
            freeze_core=False,
            orbital_reduction=[])

        qubit_op, _ = fermionic_transformation.transform(self.driver)
        self._validate_vars(fermionic_transformation, ph_energy_shift=-1.83696799)
        self._validate_info(fermionic_transformation)
        self._validate_input_object(qubit_op)
コード例 #11
0
    def test_bravyi_kitaev(self):
        """ bravyi kitaev test """
        fermionic_transformation = FermionicTransformation(
            transformation=TransformationType.FULL,
            qubit_mapping=QubitMappingType.BRAVYI_KITAEV,
            two_qubit_reduction=False,
            freeze_core=False,
            orbital_reduction=[])

        qubit_op, _ = fermionic_transformation.transform(self.driver)
        self._validate_vars(fermionic_transformation)
        self._validate_info(fermionic_transformation)
        self._validate_input_object(qubit_op)
    def test_output(self):
        """ output test """
        fermionic_transformation = \
            FermionicTransformation(transformation=TransformationType.FULL,
                                    qubit_mapping=QubitMappingType.JORDAN_WIGNER,
                                    two_qubit_reduction=False,
                                    freeze_core=False,
                                    orbital_reduction=[])

        qubit_op, _ = fermionic_transformation.transform(self.driver)
        self._validate_vars(fermionic_transformation)
        self._validate_info(fermionic_transformation)
        self._validate_input_object(qubit_op)
コード例 #13
0
    def test_freeze_core(self):
        """ freeze core test """
        fermionic_transformation = \
            FermionicTransformation(transformation=TransformationType.FULL,
                                    qubit_mapping=QubitMappingType.PARITY,
                                    two_qubit_reduction=False,
                                    freeze_core=True,
                                    orbital_reduction=[])

        qubit_op, _ = fermionic_transformation.transform(self.driver)
        self._validate_vars(fermionic_transformation, energy_shift=-7.7962196)
        self._validate_info(fermionic_transformation, num_particles=[1, 1], num_orbitals=10)
        self._validate_input_object(qubit_op, num_qubits=10, num_paulis=276)
コード例 #14
0
    def test_parity(self):
        """ parity test """
        fermionic_transformation = \
            FermionicTransformation(transformation=TransformationType.FULL,
                                    qubit_mapping=QubitMappingType.PARITY,
                                    two_qubit_reduction=True,
                                    freeze_core=False,
                                    orbital_reduction=[])

        qubit_op, _ = fermionic_transformation.transform(self.driver)
        self._validate_vars(fermionic_transformation)
        self._validate_info(fermionic_transformation, actual_two_qubit_reduction=True)
        self._validate_input_object(qubit_op, num_qubits=10)
コード例 #15
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()
コード例 #16
0
    def test_jordan_wigner_2q(self):
        """ jordan wigner 2q test """
        fermionic_transformation = FermionicTransformation(
            transformation=TransformationType.FULL,
            qubit_mapping=QubitMappingType.JORDAN_WIGNER,
            two_qubit_reduction=True,
            freeze_core=False,
            orbital_reduction=[])

        qubit_op, _ = fermionic_transformation.transform(self.driver)
        self._validate_vars(fermionic_transformation)
        # Reported effective 2 qubit reduction should be false
        self._validate_info(fermionic_transformation, actual_two_qubit_reduction=False)
        self._validate_input_object(qubit_op)
コード例 #17
0
    def test_freeze_core_all_reduction_ph(self):
        """ freeze core all reduction ph test """
        fermionic_transformation = \
            FermionicTransformation(transformation=TransformationType.PARTICLE_HOLE,
                                    qubit_mapping=QubitMappingType.PARITY,
                                    two_qubit_reduction=True,
                                    freeze_core=True,
                                    orbital_reduction=[-2, -1])

        qubit_op, _ = fermionic_transformation.transform(self.driver)
        self._validate_vars(fermionic_transformation, energy_shift=-7.7962196,
                            ph_energy_shift=-1.05785247)
        self._validate_info(fermionic_transformation, num_particles=[1, 1], num_orbitals=6,
                            actual_two_qubit_reduction=True)
        self._validate_input_object(qubit_op, num_qubits=4, num_paulis=52)
コード例 #18
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)
    def test_freeze_core_all_reduction(self):
        """ freeze core all reduction test """
        fermionic_transformation = \
            FermionicTransformation(transformation=TransformationType.FULL,
                                    qubit_mapping=QubitMappingType.PARITY,
                                    two_qubit_reduction=True,
                                    freeze_core=True,
                                    orbital_reduction=[-3, -2])

        qubit_op, _ = fermionic_transformation.transform(self.driver)
        self._validate_vars(fermionic_transformation, energy_shift=-7.7962196)
        self._validate_info(fermionic_transformation,
                            num_particles=(1, 1),
                            num_orbitals=6,
                            actual_two_qubit_reduction=True)
        self._validate_input_object(qubit_op, num_qubits=4, num_paulis=100)
コード例 #20
0
    def _run_driver(driver,
                    transformation=TransformationType.FULL,
                    qubit_mapping=QubitMappingType.JORDAN_WIGNER,
                    two_qubit_reduction=False,
                    freeze_core=True):

        fermionic_transformation = \
            FermionicTransformation(transformation=transformation,
                                    qubit_mapping=qubit_mapping,
                                    two_qubit_reduction=two_qubit_reduction,
                                    freeze_core=freeze_core,
                                    orbital_reduction=[])

        solver = NumPyMinimumEigensolver()

        gsc = GroundStateEigensolver(fermionic_transformation, solver)

        result = gsc.solve(driver)
        return result
コード例 #21
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)
コード例 #22
0
    def test_potential_interface(self):
        """Tests potential interface."""
        seed = 50
        aqua_globals.random_seed = seed

        stretch = partial(Molecule.absolute_distance, atom_pair=(1, 0))
        # H-H molecule near equilibrium geometry
        m = Molecule(geometry=[
            ['H', [0., 0., 0.]],
            ['H', [1., 0., 0.]],
        ],
                     degrees_of_freedom=[stretch],
                     masses=[1.6735328E-27, 1.6735328E-27])

        f_t = FermionicTransformation()
        driver = PySCFDriver(molecule=m)

        f_t.transform(driver)

        solver = NumPyMinimumEigensolver()

        me_gss = GroundStateEigensolver(f_t, solver)
        # Run BOPESSampler with exact eigensolution
        points = np.arange(0.45, 5.3, 0.3)
        sampler = BOPESSampler(gss=me_gss)

        res = sampler.sample(driver, points)

        # Testing Potential interface
        pot = MorsePotential(m)
        pot.fit(res.points, res.energies)

        np.testing.assert_array_almost_equal([pot.alpha, pot.r_0],
                                             [2.235, 0.720],
                                             decimal=3)
        np.testing.assert_array_almost_equal([pot.d_e, pot.m_shift],
                                             [0.2107, -1.1419],
                                             decimal=3)
コード例 #23
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=FermionicQubitMappingType.JORDAN_WIGNER)

        self.seed = 50
        self.quantum_instance = QuantumInstance(
            BasicAer.get_backend('statevector_simulator'),
            shots=1,
            seed_simulator=self.seed,
            seed_transpiler=self.seed)

        self._vqe_uccsd_factory = VQEUCCSDFactory(self.quantum_instance)
コード例 #24
0
    def test_h2_bopes_sampler(self):
        """Test BOPES Sampler on H2"""
        seed = 50
        aqua_globals.random_seed = seed

        # Molecule
        dof = partial(Molecule.absolute_distance, atom_pair=(1, 0))
        m = Molecule(geometry=[['H', [0., 0., 1.]], ['H', [0., 0.45, 1.]]],
                     degrees_of_freedom=[dof])

        f_t = FermionicTransformation()
        driver = PySCFDriver(molecule=m)

        qubitop, _ = f_t.transform(driver)

        # Quantum Instance:
        shots = 1
        backend = 'statevector_simulator'
        quantum_instance = QuantumInstance(BasicAer.get_backend(backend),
                                           shots=shots)
        quantum_instance.run_config.seed_simulator = seed
        quantum_instance.compile_config['seed_transpiler'] = seed

        # Variational form
        i_state = HartreeFock(
            num_orbitals=f_t._molecule_info['num_orbitals'],
            qubit_mapping=f_t._qubit_mapping,
            two_qubit_reduction=f_t._two_qubit_reduction,
            num_particles=f_t._molecule_info['num_particles'],
            sq_list=f_t._molecule_info['z2_symmetries'].sq_list)
        var_form = RealAmplitudes(qubitop.num_qubits,
                                  reps=1,
                                  entanglement='full',
                                  skip_unentangled_qubits=False)
        var_form.compose(i_state, front=True)

        # Classical optimizer:
        # Analytic Quantum Gradient Descent (AQGD) (with Epochs)
        aqgd_max_iter = [10] + [1] * 100
        aqgd_eta = [1e0] + [1.0 / k for k in range(1, 101)]
        aqgd_momentum = [0.5] + [0.5] * 100
        optimizer = AQGD(maxiter=aqgd_max_iter,
                         eta=aqgd_eta,
                         momentum=aqgd_momentum,
                         tol=1e-6,
                         averaging=4)

        # Min Eigensolver: VQE
        solver = VQE(var_form=var_form,
                     optimizer=optimizer,
                     quantum_instance=quantum_instance,
                     expectation=PauliExpectation())

        me_gss = GroundStateEigensolver(f_t, solver)

        # BOPES sampler
        sampler = BOPESSampler(gss=me_gss)

        # absolute internuclear distance in Angstrom
        points = [0.7, 1.0, 1.3]
        results = sampler.sample(driver, points)

        points_run = results.points
        energies = results.energies

        np.testing.assert_array_almost_equal(points_run, [0.7, 1.0, 1.3])
        np.testing.assert_array_almost_equal(
            energies, [-1.13618945, -1.10115033, -1.03518627], decimal=2)