Пример #1
0
    def test_chc_vscf(self):
        """ chc vscf test """

        co2_2modes_2modals_2body = [
            [[[[0, 0, 0]], 320.8467332810141], [[[0, 1, 1]],
                                                1760.878530705873],
             [[[1, 0, 0]], 342.8218290247543], [[[1, 1, 1]],
                                                1032.396323618631]],
            [[[[0, 0, 0], [1, 0, 0]], -57.34003649795117],
             [[[0, 0, 1], [1, 0, 0]], -56.33205925807966],
             [[[0, 1, 0], [1, 0, 0]], -56.33205925807966],
             [[[0, 1, 1], [1, 0, 0]], -60.13032761856809],
             [[[0, 0, 0], [1, 0, 1]], -65.09576309934431],
             [[[0, 0, 1], [1, 0, 1]], -62.2363839133389],
             [[[0, 1, 0], [1, 0, 1]], -62.2363839133389],
             [[[0, 1, 1], [1, 0, 1]], -121.5533969109279],
             [[[0, 0, 0], [1, 1, 0]], -65.09576309934431],
             [[[0, 0, 1], [1, 1, 0]], -62.2363839133389],
             [[[0, 1, 0], [1, 1, 0]], -62.2363839133389],
             [[[0, 1, 1], [1, 1, 0]], -121.5533969109279],
             [[[0, 0, 0], [1, 1, 1]], -170.744837386338],
             [[[0, 0, 1], [1, 1, 1]], -167.7433236025723],
             [[[0, 1, 0], [1, 1, 1]], -167.7433236025723],
             [[[0, 1, 1], [1, 1, 1]], -179.0536532281924]]
        ]

        basis = [2, 2]

        bosonic_op = BosonicOperator(co2_2modes_2modals_2body, basis)
        qubit_op = bosonic_op.mapping('direct', threshold=1e-5)

        init_state = VSCF(basis)

        num_qubits = sum(basis)
        uvcc_varform = UVCC(num_qubits, basis, [0, 1])
        excitations = uvcc_varform.excitations_in_qubit_format()
        chc_varform = CHC(num_qubits,
                          ladder=False,
                          excitations=excitations,
                          initial_state=init_state)

        backend = QuantumInstance(
            BasicAer.get_backend('statevector_simulator'),
            seed_transpiler=2,
            seed_simulator=2)
        optimizer = COBYLA(maxiter=1000)

        algo = VQE(qubit_op, chc_varform, optimizer)
        vqe_result = algo.run(backend)

        energy = vqe_result['optimal_value']

        self.assertAlmostEqual(energy, self.reference_energy, places=4)
    def get_solver(self, transformation: BosonicTransformation) -> MinimumEigensolver:
        """Returns a VQE with a UVCCSD wavefunction ansatz, based on ``transformation``.
        This works only with a ``BosonicTransformation``.

        Args:
            transformation: a bosonic qubit operator transformation.

        Returns:
            A VQE suitable to compute the ground state of the molecule transformed
            by ``transformation``.
        """

        basis = transformation.basis
        num_modes = transformation.num_modes

        if isinstance(basis, int):
            basis = [basis] * num_modes

        num_qubits = sum(basis)

        initial_state = VSCF(basis)
        var_form = UVCC(num_qubits, basis, [0, 1], initial_state=initial_state)
        vqe = VQE(var_form=var_form,
                  quantum_instance=self._quantum_instance,
                  optimizer=self._optimizer,
                  initial_point=self._initial_point,
                  gradient=self._gradient,
                  expectation=self._expectation,
                  include_custom=self._include_custom)
        return vqe
Пример #3
0
    def build_hopping_operators(self, excitations: Union[str, List[List[int]]] = 'sd') \
            -> Tuple[Dict[str, WeightedPauliOperator],
                     Dict,
                     Dict[str, List[List[int]]]]:
        """
        Args:
            excitations:

        Returns:
            Dict of hopping operators, dict of commutativity types and dict of excitation indices
        """
        exctn_types = {'s': 0, 'd': 1}

        if isinstance(excitations, str):
            degrees = [exctn_types[letter] for letter in excitations]
            excitations_list = UVCC.compute_excitation_lists(
                self._basis_size, degrees)
        else:
            excitations_list = excitations

        size = len(excitations_list)

        def _dag_list(extn_lst):
            dag_lst = []
            for lst in extn_lst:
                dag_lst.append([lst[0], lst[2], lst[1]])
            return dag_lst

        hopping_operators: Dict[str, WeightedPauliOperator] = {}
        excitation_indices = {}
        to_be_executed_list = []
        for idx in range(size):
            to_be_executed_list += [
                excitations_list[idx],
                _dag_list(excitations_list[idx])
            ]
            hopping_operators['E_{}'.format(idx)] = None
            hopping_operators['Edag_{}'.format(idx)] = None
            excitation_indices['E_{}'.format(idx)] = excitations_list[idx]
            excitation_indices['Edag_{}'.format(idx)] = _dag_list(
                excitations_list[idx])

        result = parallel_map(self._build_single_hopping_operator,
                              to_be_executed_list,
                              task_args=(self._basis_size,
                                         self._qubit_mapping),
                              num_processes=aqua_globals.num_processes)

        for key, res in zip(hopping_operators.keys(), result):
            hopping_operators[key] = res

        # This variable is required for compatibility with the FermionicTransformation
        # at the moment we do not have any type of commutativity in the bosonic case.
        type_of_commutativities: Dict[str, List[bool]] = {}

        return hopping_operators, type_of_commutativities, excitation_indices