The QuantunNewtonRaphson
allows to offload the gradient calculation of the Newton-Raphson algorithm to a variety of quantum linear solvers.
To install quantum_newton_raphson from GitHub repository, do:
git clone git@github.com:QuantumApplicationLab/quantumnewtonraphson.git
cd quantumnewtonraphson
python -m pip install .
from qiskit.primitives import Estimator, Sampler
from quantum_newton_raphson.newton_raphson import newton_raphson
from quantum_newton_raphson.hhl_solver import HHL_SOLVER
def func(input):
"""non linear function to be solved: func(x) = 0."""
...
return output
estimator = Estimator()
sampler = Sampler()
# define the linear solver with the reorder solver
solver = HHL_SOLVER(estimator=estimator, sampler=sampler)
# Solve the newton raphson problem
res = newton_raphson(
func, np.random.rand(2), linear_solver=solver, verbose=True, max_iter=25
)
If you want to contribute to the development of quantum_newton_raphson, have a look at the contribution guidelines.
This package was created with Cookiecutter and the NLeSC/python-template.