The callback for the VQC class is defined as:
callback (Optional[Callable[[ndarray, float], None]])– a reference to a user’s callback function that has two parameters and returns None. The callback can access intermediate data during training. On each iteration, an optimizer invokes the callback and passes current weights as an array and a computed value as a float of the objective function being optimized. This allows to track how well the optimization / training process is going on.
The function that I am passing to that argument is:
weights =  loss =  def store_intermediate_result(current_weights, current_loss): print(current_loss) weights.append(np.copy(current_weights)) loss.append(current_loss)
However, the loss value passed back is always the same. I had this issue before with the weights, however, when I printed the weights they were different. So it was a problem of just copying the array as you can see in the code sample. But with the loss values, they are always the same no matter what I do.
The vqc code is as follows:
vqc = VQC(feature_map=feature_map, ansatz=ansatz, loss='cross_entropy', optimizer=AQGD(maxiter=5), quantum_instance=QuantumInstance(Aer.get_backend('aer_simulator_statevector')), callback=store_intermediate_result)
EDIT: The problem seemed to be the optimiser used. COBYLA works but AQGD does not. The issue has been raised on GitHub.