qiskit-algorithms
qiskit-algorithms copied to clipboard
QNSPSA function optimize not implemented
Environment
- Qiskit Algorithms version: 0.3.0
- Python version: 3.10.9
- Operating system: Linux
What is happening?
Hi,
I want to use the optimizer QNSPSA. I used the documentation on the github page. I used the sample code in the description of the class
import numpy as np
from qiskit_algorithms.optimizers import QNSPSA
from qiskit.circuit.library import PauliTwoDesign
from qiskit.primitives import Estimator, Sampler
from qiskit.quantum_info import Pauli
# problem setup
ansatz = PauliTwoDesign(2, reps=1, seed=2)
observable = Pauli("ZZ")
initial_point = np.random.random(ansatz.num_parameters)
# loss function
estimator = Estimator()
def loss(x):
result = estimator.run([ansatz], [observable], [x]).result()
return np.real(result.values[0])
# fidelity for estimation of the geometric tensor
sampler = Sampler()
fidelity = QNSPSA.get_fidelity(ansatz, sampler)
# run QN-SPSA
qnspsa = QNSPSA(fidelity, maxiter=300)
result = qnspsa.optimize(ansatz.num_parameters, loss, initial_point=initial_point)
And, surprise... I got the error AttributeError: 'QNSPSA' object has no attribute 'optimize'
because optimize
is not implemented...
How can we reproduce the issue?
Simply run the code provided in the class description.
What should happen?
Optimization process.
Any suggestions?
Complete the class with the optimize function or update the documentation and class description in order to have a good reference to use the optimizer.