# No module named 'qiskit.algorithms.linear_solvers'

I am trying to execute HHL algorithm. I referred to the code from https://quantumpedia.uk/quantum-algorithm-4-hhl-algorithm-for-linear-systems-of-equations-40619daec41d.

I tried implementing all the required qiskit modules. The version details of the same are as follows: {'qiskit': '0.45.1', 'qiskit-aer': '0.13.1', 'qiskit-ignis': '0.7.1', 'qiskit-ibmq-provider': None, 'qiskit-nature': '0.7.1', 'qiskit-finance': None, 'qiskit-optimization': '0.6.0', 'qiskit-machine-learning': '0.7.1'}.I have also installed qiskit.algorithm version 0.2.0.

I also referred to migration quide https://qiskit.org/documentation/stable/0.28/aqua_tutorials/Qiskit%20Algorithms%20Migration%20Guide.html which says the code previously was

from qiskit.aqua.algorithms import HHL
from qiskit.aqua.components.eigs import EigsQPE
from qiskit.aqua.components.reciprocals import LookupRotation
from qiskit.aqua.components.initial_states import Custom
from qiskit.aqua.operators import MatrixOperator

def create_eigs(matrix, num_auxiliary, num_time_slices, negative_evals):
ne_qfts = [None, None]
if negative_evals:
num_auxiliary += 1
ne_qfts = [QFT(num_auxiliary - 1), QFT(num_auxiliary - 1).inverse()]
return EigsQPE(MatrixOperator(matrix=matrix),
QFT(num_auxiliary).inverse(),
num_time_slices=num_time_slices,
num_ancillae=num_auxiliary,
expansion_mode='suzuki',
expansion_order=2,
evo_time=None,
negative_evals=negative_evals,
ne_qfts=ne_qfts)

orig_size = len(vector)

matrix, vector, truncate_powerdim, truncate_hermitian = HHL.matrix_resize(matrix, vector)

# Initialize eigenvalue finding module
eigs = create_eigs(matrix, 3, 50, False)
num_q, num_a = eigs.get_register_sizes()

# Initialize initial state module
init_state = Custom(num_q, state_vector=vector)

# Initialize reciprocal rotation module
reci = LookupRotation(negative_evals=eigs._negative_evals, evo_time=eigs._evo_time)
algo = HHL(matrix, vector, truncate_powerdim, truncate_hermitian, eigs,
init_state, reci, num_q, num_a, orig_size)

result = algo.run(aqua_qinstance)
print(result.solution)


is now this:


hhl = HHL()
result = hhl.solve(matrix, vector)
result.state.draw('mpl', style='iqx')


Still, I am getting the error as "No module named 'qiskit.algorithms.linear_solvers' ". After doing some basic research on Google I even replaced qiskit.algorithms by qiskit_algorithms still no luck.

Any form of help will be appreciated

The HHL algorithm was deprecated and removed out of Qiskit some time ago: see https://docs.quantum.ibm.com/api/qiskit/release-notes/0.43#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).

The release notes linked above also pointed at some textbook that was part of learning materials. The HHL part is still here https://github.com/Qiskit/textbook/blob/main/notebooks/ch-applications/hhl_tutorial.ipynb and you can look at the section Qiskit Implementation.

HHL (the Qiskit Implementation which was) now exists in this repository https://github.com/anedumla/quantum_linear_solvers at the same state as when it was removed. You are feel to use this but bear in mind its no longer part supported as part of Qiskit and function it relies on, such as Quantum Instance, has since been deprecated in Qiskit though still exists in the latest 0.45 release but will not be there when 1.0.0 releases, as it has been removed from that.

Other algorithms that, were moved to qiskit_algorithms, now support primitives - Estimator and Sample - and do not use the former Quantum Instance to execute circuits. HHL was removed before this latter move and so is rather older code and has not been updated. So while you can use it just beware of these things.

• Thank you. But no latest document on the usage of the same is shared Commented Jan 2 at 11:39
• The notebook I linked above has a couple of examples using the code. The only other source of some examples is in the original test file here github.com/Qiskit/qiskit/blob/stable/0.23/test/python/… (on the older stable 0.23 branch before liner solvers were removed) if that helps at all. Otherwise as I said its no longer part of Qiskit nor supported by Qiskit any more. Commented Jan 2 at 14:35
• Of course that former test file that I linked in the above comment was also moved/copied to repo (linked in the answer) where the code exists now so you can refer to it from there. Commented Jan 3 at 13:42