def __init__(self):
     super().__init__()
     modes = [[605.3643675, 1, 1], [-605.3643675, -1, -1], [340.5950575, 2, 2],
              [-340.5950575, -2, -2], [-89.09086530649508, 2, 1, 1],
              [-15.590557244410897, 2, 2, 2], [1.6512647916666667, 1, 1, 1, 1],
              [5.03965375, 2, 2, 1, 1], [0.43840625000000005, 2, 2, 2, 2]]
     self._watson = WatsonHamiltonian(modes, 2)
 def setUp(self):
     """Setup basis."""
     super().setUp()
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore", category=DeprecationWarning)
         watson = WatsonHamiltonian([], -1)
     basis = HarmonicBasis([2, 3, 4])
     self.prop = OccupiedModals.from_legacy_driver_result(watson)
     self.prop.basis = basis
Beispiel #3
0
class TestSecondQuantizedProperty(QiskitNatureTestCase):
    """General Property base class tests."""

    LegacyDriverResult = Union[QMolecule, WatsonHamiltonian]

    @unpack
    @data(
        (QMolecule(), QMolecule, False),
        (QMolecule(), WatsonHamiltonian, True),
        (WatsonHamiltonian([], -1), QMolecule, True),
        (WatsonHamiltonian([], -1), WatsonHamiltonian, False),
    )
    def test_validate_input_type(
        self, result: LegacyDriverResult, type_: Any, raises_: bool
    ) -> None:
        """Test input type validation."""
        raised = False
        try:
            SecondQuantizedProperty._validate_input_type(result, type_)
        except QiskitNatureError:
            raised = True
        finally:
            self.assertEqual(raised, raises_)
    def get_watson_hamiltonian(self,
                               normalize: bool = True) -> WatsonHamiltonian:
        """
        Get the force constants as a WatsonHamiltonian
        Args:
            normalize: Whether to normalize the factors or not
        Returns:
            A WatsonHamiltonian
        """
        # Returns [value, idx0, idx1...] from 2 indices (quadratic) to 4 (quartic)
        qua = self.quadratic_force_constants
        cub = self.cubic_force_constants
        qrt = self.quartic_force_constants
        modes = []
        for entry in qua:
            indices = self._process_entry_indices(list(entry))
            if indices:
                factor = 2.0
                factor *= self._multinomial(indices) if normalize else 1.0
                line = [entry[2] / factor]
                line.extend(indices)
                modes.append(line)
                modes.append([-x for x in line])
        for entry_c in cub:
            indices = self._process_entry_indices(list(entry_c))
            if indices:
                factor = 2.0 * math.sqrt(2.0)
                factor *= self._multinomial(indices) if normalize else 1.0
                line = [entry_c[3] / factor]
                line.extend(indices)
                modes.append(line)
        for entry_q in qrt:
            indices = self._process_entry_indices(list(entry_q))
            if indices:
                factor = 4.0
                factor *= self._multinomial(indices) if normalize else 1.0
                line = [entry_q[4] / factor]
                line.extend(indices)
                modes.append(line)

        num_modes = len(self.a_to_h_numbering.keys())
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore", category=DeprecationWarning)
            watson = WatsonHamiltonian(modes, num_modes)

        return watson
 def __init__(self):
     super().__init__()
     modes = [
         [605.3643675, 1, 1],
         [-605.3643675, -1, -1],
         [340.5950575, 2, 2],
         [-340.5950575, -2, -2],
         [-89.09086530649508, 2, 1, 1],
         [-15.590557244410897, 2, 2, 2],
         [1.6512647916666667, 1, 1, 1, 1],
         [5.03965375, 2, 2, 1, 1],
         [0.43840625000000005, 2, 2, 2, 2],
     ]
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore", category=DeprecationWarning)
         watson = WatsonHamiltonian(modes, 2)
         self._driver_result = VibrationalStructureDriverResult.from_legacy_driver_result(
             watson)
Beispiel #6
0
    def _check_driver_result(self, expected_watson_data, prop):
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore", category=DeprecationWarning)
            expected_watson = WatsonHamiltonian(expected_watson_data, 4)
        expected = VibrationalEnergy.from_legacy_driver_result(expected_watson)
        true_vib_energy = cast(VibrationalEnergy, prop.get_property(VibrationalEnergy))

        with self.subTest("one-body terms"):
            expected_one_body = expected.get_vibrational_integral(1)
            true_one_body = true_vib_energy.get_vibrational_integral(1)
            self._check_integrals_are_close(expected_one_body, true_one_body)

        with self.subTest("two-body terms"):
            expected_two_body = expected.get_vibrational_integral(2)
            true_two_body = true_vib_energy.get_vibrational_integral(2)
            self._check_integrals_are_close(expected_two_body, true_two_body)

        with self.subTest("three-body terms"):
            expected_three_body = expected.get_vibrational_integral(3)
            true_three_body = true_vib_energy.get_vibrational_integral(3)
            self._check_integrals_are_close(expected_three_body, true_three_body)
 def setUp(self):
     """Setup basis."""
     super().setUp()
     basis = HarmonicBasis([2, 2, 2, 2])
     with warnings.catch_warnings():
         warnings.filterwarnings("ignore", category=DeprecationWarning)
         watson = WatsonHamiltonian(
             [
                 [352.3005875, 2, 2],
                 [-352.3005875, -2, -2],
                 [631.6153975, 1, 1],
                 [-631.6153975, -1, -1],
                 [115.653915, 4, 4],
                 [-115.653915, -4, -4],
                 [115.653915, 3, 3],
                 [-115.653915, -3, -3],
                 [-15.341901966295344, 2, 2, 2],
                 [-88.2017421687633, 1, 1, 2],
                 [42.40478531359112, 4, 4, 2],
                 [26.25167512727164, 4, 3, 2],
                 [2.2874639206341865, 3, 3, 2],
                 [0.4207357291666667, 2, 2, 2, 2],
                 [4.9425425, 1, 1, 2, 2],
                 [1.6122932291666665, 1, 1, 1, 1],
                 [-4.194299375, 4, 4, 2, 2],
                 [-4.194299375, 3, 3, 2, 2],
                 [-10.20589125, 4, 4, 1, 1],
                 [-10.20589125, 3, 3, 1, 1],
                 [2.2973803125, 4, 4, 4, 4],
                 [2.7821204166666664, 4, 4, 4, 3],
                 [7.329224375, 4, 4, 3, 3],
                 [-2.7821200000000004, 4, 3, 3, 3],
                 [2.2973803125, 3, 3, 3, 3],
             ],
             4,
         )
     self.prop = VibrationalEnergy.from_legacy_driver_result(watson)
     self.prop.basis = basis