Exemple #1
0
 def test_exact_cover(self):
     """ Exact Cover test """
     algo = NumPyMinimumEigensolver()
     result = algo.compute_minimum_eigenvalue(operator=self.qubit_op, aux_operators=[])
     x = sample_most_likely(result.eigenstate)
     ising_sol = exact_cover.get_solution(x)
     np.testing.assert_array_equal(ising_sol, [0, 1, 1, 0])
     oracle = self._brute_force()
     self.assertEqual(exact_cover.check_solution_satisfiability(ising_sol, self.list_of_subsets),
                      oracle)
Exemple #2
0
 def test_exact_cover_vqe(self):
     """ Exact Cover VQE test """
     algorithm_globals.random_seed = 10598
     q_i = QuantumInstance(BasicAer.get_backend('statevector_simulator'),
                           seed_simulator=algorithm_globals.random_seed,
                           seed_transpiler=algorithm_globals.random_seed)
     result = VQE(EfficientSU2(self.qubit_op.num_qubits, reps=5),
                  COBYLA(),
                  max_evals_grouped=2,
                  quantum_instance=q_i).compute_minimum_eigenvalue(operator=self.qubit_op)
     x = sample_most_likely(result.eigenstate)
     ising_sol = exact_cover.get_solution(x)
     oracle = self._brute_force()
     self.assertEqual(exact_cover.check_solution_satisfiability(ising_sol, self.list_of_subsets),
                      oracle)