Exemplo n.º 1
0
    def test_graph_partition_vqe(self):
        algorithm_cfg = {
            'name': 'VQE',
            'operator_mode': 'matrix',
            'batch_mode': True
        }

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

        var_form_cfg = {'name': 'RY', 'depth': 5, 'entanglement': 'linear'}

        params = {
            'problem': {
                'name': 'ising',
                'random_seed': 10598
            },
            'algorithm': algorithm_cfg,
            'optimizer': optimizer_cfg,
            'variational_form': var_form_cfg
        }
        backend = get_aer_backend('statevector_simulator')
        result = run_algorithm(params, self.algo_input, backend=backend)
        x = graphpartition.sample_most_likely(result['eigvecs'][0])
        # check against the oracle
        ising_sol = graphpartition.get_graph_solution(x)
        np.testing.assert_array_equal(ising_sol, [1, 0, 0, 1])
        oracle = self.brute_force()
        self.assertEqual(graphpartition.objective_value(x, self.w), oracle)
Exemplo n.º 2
0
 def test_graph_partition_direct(self):
     algo = ExactEigensolver(self.algo_input.qubit_op,
                             k=1,
                             aux_operators=[])
     result = algo.run()
     x = graphpartition.sample_most_likely(result['eigvecs'][0])
     # check against the oracle
     ising_sol = graphpartition.get_graph_solution(x)
     np.testing.assert_array_equal(ising_sol, [0, 1, 0, 1])
     oracle = self.brute_force()
     self.assertEqual(graphpartition.objective_value(x, self.w), oracle)
Exemplo n.º 3
0
 def test_graph_partition(self):
     params = {
         'problem': {
             'name': 'ising'
         },
         'algorithm': {
             'name': 'ExactEigensolver'
         }
     }
     result = run_algorithm(params, self.algo_input)
     x = graphpartition.sample_most_likely(result['eigvecs'][0])
     # check against the oracle
     ising_sol = graphpartition.get_graph_solution(x)
     np.testing.assert_array_equal(ising_sol, [0, 1, 0, 1])
     oracle = self.brute_force()
     self.assertEqual(graphpartition.objective_value(x, self.w), oracle)