qiskit-textbook icon indicating copy to clipboard operation
qiskit-textbook copied to clipboard

[4.1.2] Simulating Molecules using VQE

Open Hosseinberg opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe.

Qiskit aqua is now deprecated and all codes containing from qiskit.aqua.components.optimizers import COBYLA will not work unless we make some modifications in the code. For example, in the vqe-molecules.ipynb we need use from qiskit.algorithms.optimizers import COBYLA Simply changing where we import COBYLA from is not enough since we have made some changes in the optimizer class.

Describe the solution you'd like

For example, to make the first part of the vqe-molecules.ipynb to work we need to consider something like

from scipy.spatial import distance

optimizer = COBYLA(maxiter=500, tol=0.0001)

params = np.random.rand(3)
ret = optimizer.minimize(objective_function, params)

qc = get_var_form(ret.x)
t_qc = transpile(qc, backend)
qobj = assemble(t_qc, shots=NUM_SHOTS)
counts = backend.run(qobj).result().get_counts(qc)
output_distr = get_probability_distribution(counts)

print("Target Distribution:", target_distr)
print("Obtained Distribution:", output_distr)
print("Output Error (Manhattan Distance):", distance.cityblock(target_distr, output_distr))
print("Parameters Found:", ret.x)```


### Describe alternatives you've considered

`ret.x` in this new code gives the parameters found

### Additional context

_No response_

Hosseinberg avatar Jul 26 '22 02:07 Hosseinberg

Hey, @Hosseinberg thanks for opening this issue. This issue is already been addressed in #1331 but it is still not solved. Feel free to work on these issues and submit a PR fixing all this. Thanks

divshacker avatar Jul 26 '22 02:07 divshacker