Пример #1
0
    def test_set_packing_vqe(self):
        """ set packing vqe test """
        try:
            # pylint: disable=import-outside-toplevel
            from qiskit import Aer
        except Exception as ex:  # pylint: disable=broad-except
            self.skipTest(
                "Aer doesn't appear to be installed. Error: '{}'".format(
                    str(ex)))
            return

        wavefunction = TwoLocal(rotation_blocks='ry',
                                entanglement_blocks='cz',
                                reps=3,
                                entanglement='linear')
        q_i = QuantumInstance(Aer.get_backend('qasm_simulator'),
                              seed_simulator=aqua_globals.random_seed,
                              seed_transpiler=aqua_globals.random_seed)
        result = VQE(wavefunction,
                     SPSA(maxiter=200),
                     max_evals_grouped=2,
                     quantum_instance=q_i).compute_minimum_eigenvalue(
                         operator=self.qubit_op)
        x = sample_most_likely(result.eigenstate)
        ising_sol = set_packing.get_solution(x)
        oracle = self._brute_force()
        self.assertEqual(np.count_nonzero(ising_sol), oracle)
Пример #2
0
 def test_set_packing(self):
     """ set packing test """
     algo = NumPyMinimumEigensolver()
     result = algo.compute_minimum_eigenvalue(operator=self.qubit_op,
                                              aux_operators=[])
     x = sample_most_likely(result.eigenstate)
     ising_sol = set_packing.get_solution(x)
     np.testing.assert_array_equal(ising_sol, [0, 1, 1])
     oracle = self._brute_force()
     self.assertEqual(np.count_nonzero(ising_sol), oracle)