예제 #1
0
    def test_second_q_ops_without_transformers(self):
        """Tests that the list of second quantized operators is created if no transformers
        provided."""
        expected_num_of_sec_quant_ops = 5
        logfile = self.get_resource_path(
            "CO2_freq_B3LYP_ccpVDZ.log",
            "problems/second_quantization/vibrational/resources",
        )
        driver = GaussianForcesDriver(logfile=logfile)

        watson_hamiltonian = driver.run()
        num_modals = 2
        truncation_order = 3
        num_modes = watson_hamiltonian.num_modes
        num_modals = [num_modals] * num_modes
        vibrational_problem = VibrationalStructureProblem(
            driver, num_modals, truncation_order)
        second_quantized_ops = vibrational_problem.second_q_ops()
        vibrational_op = second_quantized_ops[0]
        with self.subTest(
                "Check expected length of the list of second quantized operators."
        ):
            assert len(second_quantized_ops) == expected_num_of_sec_quant_ops
        with self.subTest(
                "Check types in the list of second quantized operators."):
            assert isinstance(vibrational_op, VibrationalOp)
    def test_second_q_ops_without_transformers(self):
        """Tests that the list of second quantized operators is created if no transformers
        provided."""
        expected_num_of_sec_quant_ops = 5
        expected_len_of_vibrational_op = 47
        num_modals = 2
        truncation_order = 3
        num_modes = self.props.num_modes
        num_modals = [num_modals] * num_modes
        vibrational_problem = VibrationalStructureProblem(
            self.driver, num_modals, truncation_order)
        second_quantized_ops = vibrational_problem.second_q_ops()
        vibrational_op = second_quantized_ops[
            vibrational_problem.main_property_name]

        with self.subTest(
                "Check expected length of the list of second quantized operators."
        ):
            assert len(second_quantized_ops) == expected_num_of_sec_quant_ops
        with self.subTest("Check expected length of the vibrational op."):
            assert len(vibrational_op) == expected_len_of_vibrational_op
        with self.subTest(
                "Check types in the list of second quantized operators."):
            assert isinstance(vibrational_op, VibrationalOp)
            self.assertEqual(vibrational_op, _truncation_order_2_op)
예제 #3
0
    def test_second_q_ops_without_transformers(self):
        """Tests that the list of second quantized operators is created if no transformers
        provided."""
        expected_num_of_sec_quant_ops = 5
        logfile = self.get_resource_path(
            "CO2_freq_B3LYP_ccpVDZ.log",
            "problems/second_quantization/vibrational/resources",
        )
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore", category=DeprecationWarning)
            driver = GaussianForcesDriver(logfile=logfile)
            watson_hamiltonian = driver.run()

        num_modals = 2
        truncation_order = 3
        num_modes = watson_hamiltonian.num_modes
        num_modals = [num_modals] * num_modes
        vibrational_problem = VibrationalStructureProblem(
            driver, num_modals, truncation_order)
        second_quantized_ops = vibrational_problem.second_q_ops()
        vibrational_op = second_quantized_ops[0]

        with self.subTest("Check that the correct properties are/aren't None"):
            with warnings.catch_warnings():
                warnings.filterwarnings("ignore", category=DeprecationWarning)
                # new driver used, molecule_data* should be None
                self.assertIsNone(vibrational_problem.molecule_data)
                self.assertIsNone(
                    vibrational_problem.molecule_data_transformed)
            # converted properties should never be None
            self.assertIsNotNone(vibrational_problem.grouped_property)
            self.assertIsNotNone(
                vibrational_problem.grouped_property_transformed)

        with self.subTest(
                "Check expected length of the list of second quantized operators."
        ):
            assert len(second_quantized_ops) == expected_num_of_sec_quant_ops
        with self.subTest(
                "Check types in the list of second quantized operators."):
            assert isinstance(vibrational_op, VibrationalOp)
예제 #4
0
class TestHoppingOpsBuilder(QiskitNatureTestCase):
    """Tests Hopping Operators builder."""
    def setUp(self):
        super().setUp()
        algorithm_globals.random_seed = 8
        self.driver = _DummyBosonicDriver()
        self.qubit_converter = QubitConverter(DirectMapper())
        self.basis_size = 2
        self.truncation_order = 2

        self.vibrational_problem = VibrationalStructureProblem(
            self.driver, self.basis_size, self.truncation_order)

        self.qubit_converter = QubitConverter(DirectMapper())
        self.vibrational_problem.second_q_ops()
        self.watson_hamiltonian = self.vibrational_problem.molecule_data
        self.num_modals = [self.basis_size] * self.watson_hamiltonian.num_modes

    def test_build_hopping_operators(self):
        """Tests that the correct hopping operator is built from QMolecule."""
        # TODO extract it somewhere
        expected_hopping_operators = ({
            'E_0':
            PauliSumOp(SparsePauliOp(
                [[True, True, False, False, False, False, False, False],
                 [True, True, False, False, False, True, False, False],
                 [True, True, False, False, True, False, False, False],
                 [True, True, False, False, True, True, False, False]],
                coeffs=[0.25 + 0.j, 0. - 0.25j, 0. + 0.25j, 0.25 + 0.j]),
                       coeff=1.0),
            'Edag_0':
            PauliSumOp(SparsePauliOp(
                [[True, True, False, False, False, False, False, False],
                 [True, True, False, False, False, True, False, False],
                 [True, True, False, False, True, False, False, False],
                 [True, True, False, False, True, True, False, False]],
                coeffs=[0.25 + 0.j, 0. + 0.25j, 0. - 0.25j, 0.25 + 0.j]),
                       coeff=1.0),
            'E_1':
            PauliSumOp(SparsePauliOp(
                [[False, False, True, True, False, False, False, False],
                 [False, False, True, True, False, False, False, True],
                 [False, False, True, True, False, False, True, False],
                 [False, False, True, True, False, False, True, True]],
                coeffs=[0.25 + 0.j, 0. - 0.25j, 0. + 0.25j, 0.25 + 0.j]),
                       coeff=1.0),
            'Edag_1':
            PauliSumOp(SparsePauliOp(
                [[False, False, True, True, False, False, False, False],
                 [False, False, True, True, False, False, False, True],
                 [False, False, True, True, False, False, True, False],
                 [False, False, True, True, False, False, True, True]],
                coeffs=[0.25 + 0.j, 0. + 0.25j, 0. - 0.25j, 0.25 + 0.j]),
                       coeff=1.0),
            'E_2':
            PauliSumOp(SparsePauliOp(
                [[True, True, True, True, False, False, False, False],
                 [True, True, True, True, False, False, False, True],
                 [True, True, True, True, False, False, True, False],
                 [True, True, True, True, False, False, True, True],
                 [True, True, True, True, False, True, False, False],
                 [True, True, True, True, False, True, False, True],
                 [True, True, True, True, False, True, True, False],
                 [True, True, True, True, False, True, True, True],
                 [True, True, True, True, True, False, False, False],
                 [True, True, True, True, True, False, False, True],
                 [True, True, True, True, True, False, True, False],
                 [True, True, True, True, True, False, True, True],
                 [True, True, True, True, True, True, False, False],
                 [True, True, True, True, True, True, False, True],
                 [True, True, True, True, True, True, True, False],
                 [True, True, True, True, True, True, True, True]],
                coeffs=[
                    0.0625 + 0.j, 0. - 0.0625j, 0. + 0.0625j, 0.0625 + 0.j,
                    0. - 0.0625j, -0.0625 + 0.j, 0.0625 + 0.j, 0. - 0.0625j,
                    0. + 0.0625j, 0.0625 + 0.j, -0.0625 + 0.j, 0. + 0.0625j,
                    0.0625 + 0.j, 0. - 0.0625j, 0. + 0.0625j, 0.0625 + 0.j
                ]),
                       coeff=1.0),
            'Edag_2':
            PauliSumOp(SparsePauliOp(
                [[True, True, True, True, False, False, False, False],
                 [True, True, True, True, False, False, False, True],
                 [True, True, True, True, False, False, True, False],
                 [True, True, True, True, False, False, True, True],
                 [True, True, True, True, False, True, False, False],
                 [True, True, True, True, False, True, False, True],
                 [True, True, True, True, False, True, True, False],
                 [True, True, True, True, False, True, True, True],
                 [True, True, True, True, True, False, False, False],
                 [True, True, True, True, True, False, False, True],
                 [True, True, True, True, True, False, True, False],
                 [True, True, True, True, True, False, True, True],
                 [True, True, True, True, True, True, False, False],
                 [True, True, True, True, True, True, False, True],
                 [True, True, True, True, True, True, True, False],
                 [True, True, True, True, True, True, True, True]],
                coeffs=[
                    0.0625 + 0.j, 0. + 0.0625j, 0. - 0.0625j, 0.0625 + 0.j,
                    0. + 0.0625j, -0.0625 + 0.j, 0.0625 + 0.j, 0. + 0.0625j,
                    0. - 0.0625j, 0.0625 + 0.j, -0.0625 + 0.j, 0. - 0.0625j,
                    0.0625 + 0.j, 0. + 0.0625j, 0. - 0.0625j, 0.0625 + 0.j
                ]),
                       coeff=1.0)
        }, {}, {
            'E_0': ((0, ), (1, )),
            'Edag_0': ((1, ), (0, )),
            'E_1': ((2, ), (3, )),
            'Edag_1': ((3, ), (2, )),
            'E_2': ((0, 2), (1, 3)),
            'Edag_2': ((1, 3), (0, 2))
        })

        hopping_operators = _build_qeom_hopping_ops(self.num_modals,
                                                    self.qubit_converter)
        self.assertEqual(hopping_operators, expected_hopping_operators)
class TestHoppingOpsBuilder(QiskitNatureTestCase):
    """Tests Hopping Operators builder."""
    def setUp(self):
        super().setUp()
        algorithm_globals.random_seed = 8
        self.driver = _DummyBosonicDriver()
        self.qubit_converter = QubitConverter(DirectMapper())
        self.basis_size = 2
        self.truncation_order = 2

        self.vibrational_problem = VibrationalStructureProblem(
            self.driver, self.basis_size, self.truncation_order)

        self.qubit_converter = QubitConverter(DirectMapper())
        self.vibrational_problem.second_q_ops()
        self.watson_hamiltonian = self.vibrational_problem.grouped_property_transformed
        self.num_modals = [self.basis_size] * self.watson_hamiltonian.num_modes

    def test_build_hopping_operators(self):
        """Tests that the correct hopping operator is built from QMolecule."""
        # TODO extract it somewhere
        expected_hopping_operators = (
            {
                "E_0":
                PauliSumOp.from_list([("IIXX", 0.25), ("IIYX", 0.25j),
                                      ("IIXY", -0.25j), ("IIYY", 0.25)]),
                "Edag_0":
                PauliSumOp.from_list([("IIXX", 0.25), ("IIYX", -0.25j),
                                      ("IIXY", 0.25j), ("IIYY", 0.25)]),
                "E_1":
                PauliSumOp.from_list([("XXII", 0.25), ("YXII", 0.25j),
                                      ("XYII", -0.25j), ("YYII", 0.25)]),
                "Edag_1":
                PauliSumOp.from_list([("XXII", 0.25), ("YXII", -0.25j),
                                      ("XYII", 0.25j), ("YYII", 0.25)]),
                "E_2":
                PauliSumOp.from_list([
                    ("XXXX", 0.0625),
                    ("YXXX", 0.0625j),
                    ("XYXX", -0.0625j),
                    ("YYXX", 0.0625),
                    ("XXYX", 0.0625j),
                    ("YXYX", -0.0625),
                    ("XYYX", 0.0625),
                    ("YYYX", 0.0625j),
                    ("XXXY", -0.0625j),
                    ("YXXY", 0.0625),
                    ("XYXY", -0.0625),
                    ("YYXY", -0.0625j),
                    ("XXYY", 0.0625),
                    ("YXYY", 0.0625j),
                    ("XYYY", -0.0625j),
                    ("YYYY", 0.0625),
                ]),
                "Edag_2":
                PauliSumOp.from_list([
                    ("XXXX", 0.0625),
                    ("YXXX", -0.0625j),
                    ("XYXX", 0.0625j),
                    ("YYXX", 0.0625),
                    ("XXYX", -0.0625j),
                    ("YXYX", -0.0625),
                    ("XYYX", 0.0625),
                    ("YYYX", -0.0625j),
                    ("XXXY", 0.0625j),
                    ("YXXY", 0.0625),
                    ("XYXY", -0.0625),
                    ("YYXY", 0.0625j),
                    ("XXYY", 0.0625),
                    ("YXYY", -0.0625j),
                    ("XYYY", 0.0625j),
                    ("YYYY", 0.0625),
                ]),
            },
            {},
            {
                "E_0": ((0, ), (1, )),
                "Edag_0": ((1, ), (0, )),
                "E_1": ((2, ), (3, )),
                "Edag_1": ((3, ), (2, )),
                "E_2": ((0, 2), (1, 3)),
                "Edag_2": ((1, 3), (0, 2)),
            },
        )

        hopping_operators = _build_qeom_hopping_ops(self.num_modals,
                                                    self.qubit_converter)
        self.assertEqual(hopping_operators, expected_hopping_operators)