Exemplo n.º 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')
        result = VQE(self.qubit_op,
                     wavefunction,
                     SPSA(maxiter=200),
                     max_evals_grouped=2).run(
                         QuantumInstance(
                             Aer.get_backend('qasm_simulator'),
                             seed_simulator=aqua_globals.random_seed,
                             seed_transpiler=aqua_globals.random_seed))
        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)
Exemplo n.º 2
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

        aqua_globals.random_seed = 50
        result = VQE(self.qubit_op,
                     RY(self.qubit_op.num_qubits,
                        depth=5,
                        entanglement='linear'),
                     SPSA(max_trials=200),
                     max_evals_grouped=2).run(
                         QuantumInstance(
                             Aer.get_backend('qasm_simulator'),
                             seed_simulator=aqua_globals.random_seed,
                             seed_transpiler=aqua_globals.random_seed))
        x = sample_most_likely(result['eigvecs'][0])
        ising_sol = set_packing.get_solution(x)
        oracle = self._brute_force()
        self.assertEqual(np.count_nonzero(ising_sol), oracle)
Exemplo n.º 3
0
 def test_set_packing(self):
     """ set packing test """
     algo = NumPyMinimumEigensolver(self.qubit_op, aux_operators=[])
     result = algo.run()
     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)