def test_clique_vqe(self): algorithm_cfg = { 'name': 'VQE', 'operator_mode': 'matrix', 'max_evals_grouped': 2 } optimizer_cfg = { 'name': 'COBYLA' } 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 = BasicAer.get_backend('statevector_simulator') result = run_algorithm(params, self.algo_input, backend=backend) x = clique.sample_most_likely(len(self.w), result['eigvecs'][0]) ising_sol = clique.get_graph_solution(x) np.testing.assert_array_equal(ising_sol, [1, 1, 1, 1, 1]) oracle = self.brute_force() self.assertEqual(clique.satisfy_or_not(ising_sol, self.w, self.K), oracle)
def test_clique_direct(self): algo = ExactEigensolver(self.algo_input.qubit_op, k=1, aux_operators=[]) result = algo.run() x = clique.sample_most_likely(len(self.w), result['eigvecs'][0]) ising_sol = clique.get_graph_solution(x) np.testing.assert_array_equal(ising_sol, [1, 1, 1, 1, 1]) oracle = self.brute_force() self.assertEqual(clique.satisfy_or_not(ising_sol, self.w, self.K), oracle)
def test_clique(self): params = { 'problem': {'name': 'ising'}, 'algorithm': {'name': 'ExactEigensolver'} } result = run_algorithm(params, self.algo_input) x = clique.sample_most_likely(len(self.w), result['eigvecs'][0]) ising_sol = clique.get_graph_solution(x) np.testing.assert_array_equal(ising_sol, [1, 1, 1, 1, 1]) oracle = self.brute_force() self.assertEqual(clique.satisfy_or_not(ising_sol, self.w, self.K), oracle)
def brute_force(self): # brute-force way: try every possible assignment! def bitfield(n, L): result = np.binary_repr(n, L) return [int(digit) for digit in result] L = self.num_nodes # length of the bitstring that represents the assignment max = 2**L has_sol = False for i in range(max): cur = bitfield(i, L) cur_v = clique.satisfy_or_not(np.array(cur), self.w, self.K) if cur_v: has_sol = True break return has_sol