コード例 #1
0
    def test_freeze_core_with_remove_orbitals(self):
        """Test the `freeze_core` convenience argument in combination with `remove_orbitals`."""
        driver = HDF5Driver(hdf5_input=self.get_resource_path('BeH_sto3g.hdf5', 'transformers'))
        q_molecule = driver.run()

        trafo = FreezeCoreTransformer(freeze_core=True, remove_orbitals=[4, 5])
        q_molecule_reduced = trafo.transform(q_molecule)

        expected = HDF5Driver(hdf5_input=self.get_resource_path('BeH_sto3g_reduced.hdf5',
                                                                'transformers')).run()

        self.assertQMolecule(q_molecule_reduced, expected, dict_key='FreezeCoreTransformer')
コード例 #2
0
    def test_freeze_core(self):
        """Test the `freeze_core` convenience argument."""
        driver = HDF5Driver(hdf5_input=self.get_resource_path('LiH_sto3g.hdf5', 'transformers'))
        q_molecule = driver.run()

        trafo = FreezeCoreTransformer(freeze_core=True)
        q_molecule_reduced = trafo.transform(q_molecule)

        expected = HDF5Driver(hdf5_input=self.get_resource_path('LiH_sto3g_reduced.hdf5',
                                                                'transformers')).run()

        self.assertQMolecule(q_molecule_reduced, expected, dict_key='FreezeCoreTransformer')
コード例 #3
0
    def test_freeze_core(self):
        """Test the `freeze_core` convenience argument."""
        driver = HDF5Driver(hdf5_input=self.get_resource_path(
            "LiH_sto3g.hdf5", "transformers/second_quantization/electronic"))
        q_molecule = driver.run()

        trafo = FreezeCoreTransformer(freeze_core=True)
        q_molecule_reduced = trafo.transform(q_molecule)

        expected = HDF5Driver(hdf5_input=self.get_resource_path(
            "LiH_sto3g_reduced.hdf5",
            "transformers/second_quantization/electronic")).run()

        self.assertQMolecule(q_molecule_reduced,
                             expected,
                             dict_key="FreezeCoreTransformer")
コード例 #4
0
    def setUp(self):
        super().setUp()
        self.driver = PySCFDriver(atom='H 0 0 0.735; H 0 0 0', basis='631g')

        self.qubit_converter = QubitConverter(ParityMapper(), two_qubit_reduction=True)

        self.electronic_structure_problem = ElectronicStructureProblem(self.driver,
                                                                       [FreezeCoreTransformer()])

        self.num_spin_orbitals = 8
        self.num_particles = (1, 1)

        # because we create the initial state and ansatzes early, we need to ensure the qubit
        # converter already ran such that convert_match works as expected
        _ = self.qubit_converter.convert(self.electronic_structure_problem.second_q_ops()[0],
                                         self.num_particles)

        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]]]
コード例 #5
0
 def test_lih_uhf(self):
     """ lih uhf test """
     driver = PySCFDriver(atom=self.lih, unit=UnitsType.ANGSTROM,
                          charge=0, spin=0, basis='sto-3g',
                          hf_method=HFMethodType.UHF)
     result = self._run_driver(driver, transformers=[FreezeCoreTransformer()])
     self._assert_energy_and_dipole(result, 'lih')
コード例 #6
0
    def test_full_active_space(self, kwargs):
        """Test that transformer has no effect when all orbitals are active."""
        driver = HDF5Driver(hdf5_input=self.get_resource_path('H2_sto3g.hdf5', 'transformers'))
        q_molecule = driver.run()

        # The references which we compare too were produced by the `ActiveSpaceTransformer` and,
        # thus, the key here needs to stay the same as in that test case.
        q_molecule.energy_shift['ActiveSpaceTransformer'] = 0.0
        q_molecule.x_dip_energy_shift['ActiveSpaceTransformer'] = 0.0
        q_molecule.y_dip_energy_shift['ActiveSpaceTransformer'] = 0.0
        q_molecule.z_dip_energy_shift['ActiveSpaceTransformer'] = 0.0

        trafo = FreezeCoreTransformer(**kwargs)
        q_molecule_reduced = trafo.transform(q_molecule)

        self.assertQMolecule(q_molecule_reduced, q_molecule, dict_key='FreezeCoreTransformer')
コード例 #7
0
 def test_oh_with_atoms(self):
     """ OH with num_atoms test """
     driver = FCIDumpDriver(self.get_resource_path(
         'test_driver_fcidump_oh.fcidump', 'drivers/fcidumpd'),
                            atoms=['O', 'H'])
     result = self._run_driver(driver,
                               transformers=[FreezeCoreTransformer()])
     self._assert_energy(result, 'oh')
コード例 #8
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,
                               converter=QubitConverter(BravyiKitaevMapper()),
                               transformers=[FreezeCoreTransformer()])
     self._assert_energy_and_dipole(result, 'lih')
コード例 #9
0
 def test_oh_with_atoms(self):
     """OH with num_atoms test"""
     driver = FCIDumpDriver(
         self.get_resource_path("test_driver_fcidump_oh.fcidump",
                                "drivers/second_quantization/fcidumpd"),
         atoms=["O", "H"],
     )
     result = self._run_driver(driver,
                               transformers=[FreezeCoreTransformer()])
     self._assert_energy(result, "oh")
コード例 #10
0
 def test_lih_with_atoms(self):
     """LiH with num_atoms test"""
     driver = FCIDumpDriver(
         self.get_resource_path("test_driver_fcidump_lih.fcidump",
                                "drivers/fcidumpd"),
         atoms=["Li", "H"],
     )
     result = self._run_driver(driver,
                               transformers=[FreezeCoreTransformer()])
     self._assert_energy(result, "lih")
コード例 #11
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,
                               converter=QubitConverter(ParityMapper(),
                                                        two_qubit_reduction=True),
                               transformers=[FreezeCoreTransformer()])
     self._assert_energy_and_dipole(result, 'lih')
コード例 #12
0
 def test_oh_freeze_core(self):
     """ OH freeze core test """
     with self.assertLogs('qiskit_nature', level='WARNING') as log:
         driver = FCIDumpDriver(
             self.get_resource_path('test_driver_fcidump_oh.fcidump',
                                    'drivers/fcidumpd'))
         result = self._run_driver(driver,
                                   transformers=[FreezeCoreTransformer()])
         self._assert_energy(result, 'oh')
     warning = 'WARNING:qiskit_nature.drivers.qmolecule:Missing molecule information! ' \
               'Returning empty core orbital list.'
     self.assertIn(warning, log.output)
コード例 #13
0
 def test_oh_freeze_core(self):
     """OH freeze core test"""
     with self.assertLogs("qiskit_nature", level="WARNING") as log:
         driver = FCIDumpDriver(
             self.get_resource_path("test_driver_fcidump_oh.fcidump",
                                    "drivers/second_quantization/fcidumpd"))
         result = self._run_driver(driver,
                                   transformers=[FreezeCoreTransformer()])
         self._assert_energy(result, "oh")
     warning = (
         "WARNING:qiskit_nature.drivers.qmolecule:Missing molecule information! "
         "Returning empty core orbital list.")
     self.assertIn(warning, log.output)
コード例 #14
0
 def test_lih_rhf_parity(self):
     """lih rhf parity 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,
         converter=QubitConverter(ParityMapper()),
         transformers=[FreezeCoreTransformer()],
     )
     self._assert_energy_and_dipole(result, "lih")
コード例 #15
0
 def test_lih_uhf(self):
     """ lih uhf test """
     driver = PSI4Driver(config=self.psi4_lih_config.format('uhf'))
     result = self._run_driver(driver,
                               transformers=[FreezeCoreTransformer()])
     self._assert_energy_and_dipole(result, 'lih')
コード例 #16
0
 def test_oh_uhf(self):
     """oh uhf test"""
     driver = GaussianDriver(config=self.g16_oh_config.format("uhf"))
     result = self._run_driver(driver,
                               transformers=[FreezeCoreTransformer()])
     self._assert_energy_and_dipole(result, "oh")