Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHL Algorithm gives incorrect answer #11292

Closed
MrEightL opened this issue Nov 22, 2023 · 1 comment
Closed

HHL Algorithm gives incorrect answer #11292

MrEightL opened this issue Nov 22, 2023 · 1 comment
Labels
bug Something isn't working mod: algorithms Related to the Algorithms module

Comments

@MrEightL
Copy link

MrEightL commented Nov 22, 2023

Environment

  • Qiskit Terra version: 0.25.3
  • Python version: 3.9.18
  • Operating system: Windows

What is happening?

Hello, I am trying to compare the HHL algorithm to classical methods. I'm testing the algorithm for a 2x2 case where A and b are:

matrix = np.array([ [19.98, -10], [-10, 19.98] ])
vector = np.array([-2.8653, 0.6344])

Running the algorithms give:

full naive solution vector: [-0.1197614   0.13218384]`
classical state: [-0.17013578 -0.05340129]

There seems to be a rather large discrepancy in the results. When I rounded each element of the matrix to an integer, the answer was correct again. I'm not sure what would cause this error.

How can we reproduce the issue?

Here's my code:

import numpy as np
from linear_solvers import NumPyLinearSolver, HHL
from qiskit.quantum_info import Statevector
from matplotlib import pyplot as plt
matrix = np.array([ [19.98, -10], [-10, 19.98] ])
vector = np.array([-2.8653, 0.6344])
naive_hhl_solution = HHL().solve(matrix/(np.linalg.norm(vector)), vector/(np.linalg.norm(vector)))
classical_solution = NumPyLinearSolver().solve(matrix, vector)
def get_solution_vector(solution):
    """Extracts and normalizes simulated state vector
    from LinearSolverResult."""
    solution_vector = Statevector(solution.state).data[16:18].real
    norm = solution.euclidean_norm
    return norm * solution_vector / np.linalg.norm(solution_vector)
print('full naive solution vector:',get_solution_vector(naive_hhl_solution))
print('classical state:', classical_solution.state)

Any help would be greatly appreciated.
Thanks!

What should happen?

Please explain why the HHL algorithm results in this disagreement between the results.

Any suggestions?

No response

Tasks

No tasks being tracked yet.
@MrEightL MrEightL added the bug Something isn't working label Nov 22, 2023
@woodsp-ibm
Copy link
Member

woodsp-ibm commented Nov 22, 2023

HHL was deprecated and removed from Qiskit some time back and is no longer supported https://qiskit.org/documentation/legacy_release_notes.html#algorithms-upgrade-notes

The deprecated modules factorizers and linear_solvers, containing HHL and Shor have been removed from qiskit.algorithms. These functionalities were originally deprecated as part of the 0.22.0 release (released on October 13, 2022). You can access the code through the Qiskit Textbook instead: Linear Solvers (HHL) , Factorizers (Shor)

As you will find in the textbook for HHL the code that was in Qiskit was relocated here https://github.com/anedumla/quantum_linear_solvers and I created an issue there linking to the set of issues in HHL that were still unresolved at the time which were simply closed when the code was removed #9832 You might find a similar issue there with some info.

I will also note that qiskit.algorithms was deprecated and had already been removed from the main branch here in readiness for the next release. The function was moved here to separate pkg/repo https://github.com/qiskit-community/qiskit-algorithms - that does not include HHL either since it had already been removed at the time the code was relocated.

As this code no longer exists and is no longer supported I am closing this. If your code comes from the other repository I suggest opening the issue there although I am not sure if there is any activity there any more either.

@woodsp-ibm woodsp-ibm closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2023
@woodsp-ibm woodsp-ibm added the mod: algorithms Related to the Algorithms module label Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mod: algorithms Related to the Algorithms module
Projects
None yet
Development

No branches or pull requests

2 participants