def test_set_packing_vqe(self):
        try:
            from qiskit import Aer
        except Exception as e:
            self.skipTest(
                "Aer doesn't appear to be installed. Error: '{}'".format(
                    str(e)))
            return

        algorithm_cfg = {
            'name': 'VQE',
            'operator_mode': 'grouped_paulis',
            'max_evals_grouped': 2
        }

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

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

        params = {
            'problem': {
                'name': 'ising',
                'random_seed': 100
            },
            'algorithm': algorithm_cfg,
            'optimizer': optimizer_cfg,
            'variational_form': var_form_cfg
        }
        backend = Aer.get_backend('qasm_simulator')
        result = run_algorithm(params, self.algo_input, backend=backend)
        x = setpacking.sample_most_likely(len(self.list_of_subsets),
                                          result['eigvecs'][0])
        ising_sol = setpacking.get_solution(x)
        oracle = self.brute_force()
        self.assertEqual(np.count_nonzero(ising_sol), oracle)
Exemple #2
0
    def test_set_packing_vqe(self):
        algorithm_cfg = {
            'name': 'VQE',
            'operator_mode': 'grouped_paulis',
            'batch_mode': True
        }

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

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

        params = {
            'problem': {
                'name': 'ising',
                'random_seed': 100
            },
            'algorithm': algorithm_cfg,
            'optimizer': optimizer_cfg,
            'variational_form': var_form_cfg
        }
        backend = Aer.get_backend('qasm_simulator')
        result = run_algorithm(params, self.algo_input, backend=backend)
        x = setpacking.sample_most_likely(len(self.list_of_subsets),
                                          result['eigvecs'][0])
        ising_sol = setpacking.get_solution(x)
        oracle = self.brute_force()
        self.assertEqual(np.count_nonzero(ising_sol), oracle)
Exemple #3
0
 def test_set_packing_direct(self):
     algo = ExactEigensolver(self.algo_input.qubit_op, k=1, aux_operators=[])
     result = algo.run()
     x = setpacking.sample_most_likely(len(self.list_of_subsets), result['eigvecs'][0])
     ising_sol = setpacking.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)
Exemple #4
0
 def test_set_packing(self):
     params = {
         'problem': {'name': 'ising'},
         'algorithm': {'name': 'ExactEigensolver'}
     }
     result = run_algorithm(params, self.algo_input)
     x = setpacking.sample_most_likely(len(self.list_of_subsets), result['eigvecs'][0])
     ising_sol = setpacking.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)