Esempio n. 1
0
    def test_vertex_cover_vqe(self):
        algorithm_cfg = {
            'name': 'VQE',
            'operator_mode': 'grouped_paulis',
            'max_evals_grouped': 2
        }

        optimizer_cfg = {'name': 'SPSA', 'max_trials': 200}

        var_form_cfg = {
            'name': 'RYRZ',
            'depth': 3,
        }

        params = {
            'problem': {
                'name': 'ising',
                'random_seed': 100
            },
            'algorithm': algorithm_cfg,
            'optimizer': optimizer_cfg,
            'variational_form': var_form_cfg
        }
        backend = BasicAer.get_backend('qasm_simulator')
        result = run_algorithm(params, self.algo_input, backend=backend)
        x = vertex_cover.sample_most_likely(len(self.w), result['eigvecs'][0])
        sol = vertex_cover.get_graph_solution(x)
        oracle = self.brute_force()
        self.assertEqual(np.count_nonzero(sol), oracle)
Esempio n. 2
0
 def test_vertex_cover_direct(self):
     algo = ExactEigensolver(self.algo_input.qubit_op,
                             k=1,
                             aux_operators=[])
     result = algo.run()
     x = vertex_cover.sample_most_likely(len(self.w), result['eigvecs'][0])
     sol = vertex_cover.get_graph_solution(x)
     np.testing.assert_array_equal(sol, [0, 1, 1])
     oracle = self.brute_force()
     self.assertEqual(np.count_nonzero(sol), oracle)
Esempio n. 3
0
    def test_vertex_cover(self):
        params = {
            'problem': {
                'name': 'ising'
            },
            'algorithm': {
                'name': 'ExactEigensolver'
            }
        }
        result = run_algorithm(params, self.algo_input)

        x = vertex_cover.sample_most_likely(len(self.w), result['eigvecs'][0])
        sol = vertex_cover.get_graph_solution(x)
        np.testing.assert_array_equal(sol, [0, 1, 1])
        oracle = self.brute_force()
        self.assertEqual(np.count_nonzero(sol), oracle)