Qiskit / qiskit-tutorials

A collection of Jupyter notebooks showing how to use the Qiskit SDK
Apache License 2.0
2.33k stars 1.29k forks source link

aqua classical_optimization tutorial using real quantum computer #342

Closed zzhan127 closed 6 years ago

zzhan127 commented 6 years ago

Description

I am working on the classical_optimization in aqua directory. It works well using qasm_simulator. However, when changing params['backend']['name'] = 'qasm_simulator' to params['backend']['name'] = 'ibmqx4' or params['backend']['name'] = 'ibmq_16_melbourne', the code runs endlessly and starts creating jobs on the quantum computer again and again. Then, when I check the histogram results of jobs, it seems that I cannot find the right solution according to the simulation because the probability of each output are similar. Did I make any mistake during the process?

Your Environment

Thanks a lot!

zzhan127 commented 6 years ago

screenshot from 2018-10-15 22-31-00 The left is the plot of real ibmqx4 result and the right one is the qasm_simulator result.

chunfuchen commented 6 years ago

There are a couple of things:

  1. VQE underlying creates the circuits for each iteration, so you will see the multiple job creation.
  2. The results on the simulator and real hardware could be different since the tutorials run the example on a noise-free simulation. You might need to apply some technique to mitigate those errors when you experimenting on a real device.
zzhan127 commented 6 years ago

There are a couple of things:

  1. VQE underlying creates the circuits for each iteration, so you will see the multiple job creation.
  2. The results on the simulator and real hardware could be different since the tutorials run the example on a noise-free simulation. You might need to apply some technique to mitigate those errors when you experimenting on a real device.

Thanks. I will investigate more on how to mitigate the errors in real device.

But when I run this part using 'ibmq_16_melbourne' in jupyter,

# run quantum algorithm with shots
params['algorithm']['operator_mode'] = 'grouped_paulis'
params['backend']['name'] = 'ibmq_16_melbourne'
params['backend']['shots'] = 4086

result = run_algorithm(params, algo_input)
x = maxcut.sample_most_likely(result['eigvecs'][0])
print('energy:', result['energy'])
print('time:', result['eval_time'])
print('maxcut objective:', result['energy'] + offset)
print('solution:', maxcut.get_graph_solution(x))
print('solution objective:', maxcut.maxcut_value(x, w))
plot_histogram(result['eigvecs'][0])

colors = ['r' if maxcut.get_graph_solution(x)[i] == 0 else 'b' for i in range(n)]
nx.draw_networkx(G, node_color=colors, node_size=600, alpha = .8, pos=pos)

It runs endlessly and I cannot get final results after running a whole night, do you know what happens here?

chunfuchen commented 6 years ago

I think it is because your job is queued for a long time. You can turn on the aqua logging to see the progress of optimization.

like

import logging
from qiskit_aqua._logging import set_logging_config, build_logging_config
set_logging_config(build_logging_config(logging.INFO))