machine-learningquantum-computingqiskit

Ways to get intermediate steps during optimization process in qiskit.algorithms.optimizers.ADAM


Is there any way to get the intermediate steps (similar to the callback functions in Tensorflow or Pytorch Adams optimizer) when using Qiskit's internal ADAM optimizer?

I am implementing a Variational Quantum Circuit(VQC) to train the quantum machine learning model using Qiskit's Adam optimizer.

I looked through the document of ADAM optimizer in Qiskit, but I could not find the appropriate methods to get them.

I could get the intermediate training information with the Pytorch Adam optimizer, but I wanted to know whether I could do it with Qiskit.

I am using qiskit v0.45.2.


Solution

  • As you observed the ADAM optimizer in Qiskit Algorithms does not have a callback like the other optimizers. It has been noted in this issue https://github.com/qiskit-community/qiskit-algorithms/issues/60 which was more around unification of the signatures of the optimizers, in qiskit algorithms, so it's consistent over the set of them. Now ADAM does have a snapshot_dir parameters which can be used to have its internal parameters saved if that is of use at all for you now.

    The source to ADAM is here https://github.com/qiskit-community/qiskit-algorithms/blob/main/qiskit_algorithms/optimizers/adam_amsgrad.py so you can see what it does. It was moved out of Qiskit and qiskit.algorithms as part of the move to have a separate repository/package for qiskit algorithms. With the source you could always make a copy and edit it to add a callback for yourself, if that's important for you to have.