Closed ankit27kh closed 2 years ago
Hi @ankit27kh, thank you! We have a demonstration showcasing how to use PennyLane with SPSA optimization. In the demo, the noisyopt
package is used as it integrates well with PennyLane.
Would it be beneficial if PennyLane came with a dedicated SPSA optimizer?
Hi @antalszava, thanks for the link. I wasn't aware of this. I would still suggest having SPSA built into PennyLane as it is advantageous for optimisations in the quantum world and should be available without needing to install additional libraries. After integration, it should work like other optimisers:
opt = qml.SPSA()
for _ in range(10):
params = opt.step(cost, params)
What I like about PennyLane optimisers is the ability to have granular control over the iterations. This is usually missing from other libraries like qiskit
and scipy
. Sometimes you can use callback functions, but it's not the same.
I hope we can have SPSA in PennyLane so that we still enjoy a high degree of control over the optimisation process.
Hi @ankit27kh, thank you so much for this feedback! In fact, we've been considering adding a dedicated SPSA optimizer to PennyLane. Good to hear that there would be value in such an addition. :+1:
I am not sure what is required for the use cases of hybrid quantum-classical workflow, because as far as I know, in those cases, the optimizers used are the ones of the classical platforms, i.e. tf.keras.optimizers.Adam
Hi @ixime, the part on quantum classical workflows just means to mention in the docstring of the optimizer the fact that SPSA can be particularly beneficial when optimizing workflows that are using noisy quantum devices.
Hi @ankit27kh,
I would like to contribute a tutorial for simulated annealing using PennyLane. Can be converted in a module too. Can I do it under UnitaryHack?
Hi @maxwell04-wq, you're welcome to contribute a tutorial to our qml repo! However this repo is not participating in UnitaryHACK.
I would encourage you to make a new issue on this repo (not the qml repo) if you want to contribute your module to PennyLane and participate in UnitaryHACK!
Feature details
The Simultaneous Perturbation Stochastic Approximation (SPSA) optimisation method is a faster optimisation method.
It is also naturally suited for noisy measurements. Thus, it will be useful when simulating noisy systems.
The theory (and implementation) for SPSA is:
Furthermore, it is implemented:
noisyopt
package, specifically see the source code here;Implementation and acceptance criteria
1. Implementation
There exists a
qml.SPSAOptimizer
optimizer that:compute_grad
and theapply_grad
methods (seeGradientDescentOptimizer.apply_grad
doc andGradientDescentOptimizer.compute_grad
doc);step
method (seeGradientDescentOptimizer.step
doc);step_and_cost
method (seeGradientDescentOptimizer.step_and_cost
doc);SPSAOptimizer
allows passing values to the quantities that greatly influence the optimization, including:a
: scaling parameter for step size;A
: stability constant;c
: scaling parameter for evaluation step size;alpha
: scaling exponent for step size;gamma
: scaling exponent for evaluation step size; but also defines defaults suggested in the paper. Such defaults may be of the most practical use in many use cases. E.g.,noisyopt
also uses such defaults, except forA
that is "fixed" based on the number of iteration steps.2. Testing
Test the
SPSAOptimizer
class similar to howGradientDescentOptimizer
andQNGOptimizer
are being tested.3. Documentation
The documentation of the optimizer should be similar in fashion to the documentation of the
QNGOptimizer
.The docstring of
qml.SPSAOptimizer
should:QNGOptimizer
.How important would you say this feature is?
2: Somewhat important. Needed this quarter.
Additional information
https://www.jhuapl.edu/SPSA/