Exemplo n.º 1
0
    def test_vertex_cover_vqe(self):
        """ Vertex Cover VQE test """
        algorithm_cfg = {'name': 'VQE', 'max_evals_grouped': 2}

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

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

        params = {
            'problem': {
                'name': 'ising',
                'random_seed': self.seed
            },
            '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 = sample_most_likely(result['eigvecs'][0])
        sol = vertex_cover.get_graph_solution(x)
        oracle = self._brute_force()
        self.assertEqual(np.count_nonzero(sol), oracle)
Exemplo n.º 2
0
 def test_vertex_cover_direct(self):
     """ Vertex Cover Direct test """
     algo = ExactEigensolver(self.qubit_op, k=1, aux_operators=[])
     result = algo.run()
     x = sample_most_likely(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)
Exemplo n.º 3
0
 def test_vertex_cover(self):
     """ Vertex Cover test """
     algo = NumPyMinimumEigensolver(self.qubit_op, aux_operators=[])
     result = algo.run()
     x = sample_most_likely(result.eigenstate)
     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)
Exemplo n.º 4
0
    def test_vertex_cover(self):
        """ Vertex cover test """
        params = {
            'problem': {'name': 'ising'},
            'algorithm': {'name': 'ExactEigensolver'}
        }
        result = run_algorithm(params, EnergyInput(self.qubit_op))

        x = sample_most_likely(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)
Exemplo n.º 5
0
    def test_vertex_cover_vqe(self):
        """ Vertex Cover VQE test """
        aqua_globals.random_seed = self.seed

        result = VQE(self.qubit_op,
                     RYRZ(self.qubit_op.num_qubits, depth=3),
                     SPSA(max_trials=200),
                     max_evals_grouped=2).run(
                         QuantumInstance(BasicAer.get_backend('qasm_simulator'),
                                         seed_simulator=aqua_globals.random_seed,
                                         seed_transpiler=aqua_globals.random_seed))

        x = sample_most_likely(result['eigvecs'][0])
        sol = vertex_cover.get_graph_solution(x)
        oracle = self._brute_force()
        self.assertEqual(np.count_nonzero(sol), oracle)