Closed HuangJunye closed 5 months ago
I ran this on a real system and verified that the new code works as intended. No callback function is required to store intermediate results.
it is currently 10000 (has an unwanted )
That's not a typo. Python allows underscores in numbers, which makes large numbers much easier to read.
This is new to me. Still looks weird to me though.
URL to the relevant documentation
Source: https://github.com/Qiskit/documentation/blob/main/tutorials/variational-quantum-eigensolver/vqe.ipynb Webpage: https://learning.quantum.ibm.com/tutorial/variational-quantum-eigensolver#step-3-execute-using-qiskit-primitives
Select all that apply
Describe the fix.
In the VQE tutorial, there is a callback function which has the purpose of storing intermediate results. However, due to scipy's API, only the current vector / parameters can be passed in the callback function, not the cost. Therefore, the tutorial re-run estimator again with the parameters and observables to obtain the cost which was already calculated in the cost function in each iteration. As a result, each iteration the estimator is ran twice: once for the real usage inside the cost function, and then again for the sole purpose of showing the intermediate result
The callback function is in fact redundant. We can achieve storing intermediate results without callback and without running estimator twice in each iteration. We can simply pass the dictionary for storing intermediate results in the cost function
cost_func
Fix
and in a later cell where the session is created and minimizing loop is run, pass
callback_dict
toargs
of theminimize
functionBy the way there is a typo for the default_shots, it is currently
10_000
(has an unwanted_
)