Beispiel #1
0
 def test_set_packing_direct(self):
     algo = ExactEigensolver(self.algo_input.qubit_op, k=1, aux_operators=[])
     result = algo.run()
     x = set_packing.sample_most_likely(len(self.list_of_subsets), result['eigvecs'][0])
     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)
Beispiel #2
0
 def test_set_packing(self):
     params = {
         'problem': {'name': 'ising'},
         'algorithm': {'name': 'ExactEigensolver'}
     }
     result = run_algorithm(params, self.algo_input)
     x = set_packing.sample_most_likely(len(self.list_of_subsets), result['eigvecs'][0])
     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)
Beispiel #3
0
    def test_set_packing_vqe(self):
        """ set packing vqe test """
        try:
            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

        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 = set_packing.sample_most_likely(len(self.list_of_subsets),
                                           result['eigvecs'][0])
        ising_sol = set_packing.get_solution(x)
        oracle = self._brute_force()
        self.assertEqual(np.count_nonzero(ising_sol), oracle)