<jupyter_start><jupyter_text>Test QAOA with 3 qubit problem on simulator and real device.We will create the ideal circuit with the help of IBMQ by using QAOA in qiskit terra.Then we transpile the circuit to be used on real device.For both we will show the measurement outcome.<jupyter_code>import warnings
import numpy as np
from qiskit import IBMQ, execute, transpile, BasicAer
from qiskit_optimization.algorithms import CplexOptimizer
from qiskit_optimization import QuadraticProgram
from qiskit.visualization import plot_histogram
from qiskit.providers.ibmq.job import job_monitor

from utilities.helpers import create_qaoa_meo
# select linear program to solve
qp = QuadraticProgram()
qp.read_from_lp_file("example.lp")
# solve classically as reference
cplex = CplexOptimizer()
print(cplex.solve(qp))
print(qp)
# solve qp with Minimum Eigen Optimizer and QAOA
SHOTS = 1024
EVALUATIONS = 5
def qaoa_callback(eval_ct: int, opt_pars: np.ndarray, mean: float, stdev: float) -> None:
    """Print parameterset of last iteration."""
    if eval_ct == EVALUATIONS:
        print("Evaluation count reached ", eval_ct, "with pars:", opt_pars)

warnings.filterwarnings("ignore", category=DeprecationWarning)
qaoa = create_qaoa_meo(max_iter=EVALUATIONS, qaoa_callback=qaoa_callback, shots=SHOTS)
res = qaoa.solve(qp)
res
circuit = qaoa.min_eigen_solver.get_optimal_circuit()
circuit.measure_all()
result_meas = execute(circuit, BasicAer.get_backend('qasm_simulator'), shots=SHOTS)
counts = result_meas.result().get_counts()
plot_histogram(counts)
circuit.draw()
# to this later for belem!
for meas, count in sorted(counts.items(), key= lambda item: item[1], reverse=True):
    print(meas[::-1]," : ",count) # x0, x1, x2 sorted by count
backend = least_busy(provider.backends(filters=lambda x: x.configuration().n_qubits >= 3
                                    and not x.configuration().simulator
                                    and x.status().operational==True))
print(backend)
job = execute(circuit, backend, shots=shots, job_name="qaoa_3_real", job_tags=["qaoa", "least busy"])
job_monitor(job)
counts = job.result().get_counts()
plot_histogram(counts)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09949564419990829, 'fraction_numerical': 0.005960568546538285, 'mean_word_length': 5.2881844380403455, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '417552', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 741, 'n_tokens_neox': 705, 'n_words': 195, 'path': 'comparison/Qiskit/LinearProgramming/QAOA/Example/three_var_problem/Example_Circuit.ipynb', 'repo_name': 'tomtuamnuq/compare-qiskit-ocean', 'size': '2181'}