Qiskit Aqua has a module that implements the HHL algorithm:
https://qiskit.org/documentation/stable/0.32/stubs/qiskit.aqua.algorithms.HHL.html
How does one draw the implemented circuit?
*** EDIT *** I'm working with an example from the github. I modified it as follows:
#
# Example from
# https://github.com/Qiskit/qiskit-iqx-tutorials/blob/master/qiskit/advanced/aqua/linear_systems_of_equations.ipynb
#
from qiskit.aqua import run_algorithm
from qiskit.aqua.input import LinearSystemInput
from qiskit.quantum_info import state_fidelity
from qiskit.aqua.algorithms.classical import ExactLSsolver
import numpy as np
params = {
'problem': {
'name': 'linear_system'
},
'algorithm': {
'name': 'HHL'
},
'eigs': {
'expansion_mode': 'suzuki',
'expansion_order': 2,
'name': 'EigsQPE',
'num_ancillae': 3,
'num_time_slices': 50
},
'reciprocal': {
'name': 'Lookup'
},
'backend': {
'provider': 'qiskit.BasicAer',
'name': 'statevector_simulator'
}
}
# The 2 x 2 System to solve
#
matrix = [[1, 0], [0, 2]]
vector = [1, 4]
params['input'] = {
'name': 'LinearSystemInput',
'matrix': matrix,
'vector': vector
}
# Run the HHL Algorithm
result = run_algorithm(params)
result
is the following:
{'probability_result': 0.024629684664855277,
'output': array([0.46919178+0.00000000e+00j, 0.8830963 -6.70000184e-15j]),
'solution': array([1.05859322-8.03148712e-15j, 1.99244701-3.02331663e-14j]),
'matrix': array([[1, 0],
[0, 2]]),
'vector': array([1, 4]),
'circuit_info': {'size': 28870,
'depth': 28820,
'width': 7,
'qubits': 7,
'bits': 0,
'factors': 1,
'operations': {'u3': 6011,
'u1': 8021,
'cx': 14066,
'barrier': 700,
'u2': 6,
'cu3': 42,
'x': 24}
}
}
I tried the following
HHL.construct_circuit(result.circuit_info).draw()
but that resulted in
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-13-4cf1b322ed4c> in <module>
----> 1 HHL.construct_circuit(result.circuit_info).draw()
NameError: name 'HHL' is not defined
So it may very well be that I didn't import something or that I just don't understand the syntax for the HHL.
So how should I form the instructions to generate the circuit? (I'm not very good at python so if this question is trivial, I do apologize.) I checked the qiskit documentation but I couldn't understand it well. It didn't give an explicit example so if there's something I need to learn to be able to do this, please let me know. Thank you for your time.