Closed Del012 closed 5 years ago
@Del012 could you provide the link to the notebook you used?
That branch of the tutorials repo isn't kept in sync with the latest development version of Aqua
could you try https://github.com/manoelmarques/qiskit-tutorials/tree/aqua0.5/qiskit/finance
Yeah I tried it and that one works. My apologies, I wasn't aware that there were updated versions of the tutorials.
The main qiskit tutorials repository works with the official release from PyPI. It can be hard to keep these up to date with the development of the code hence the choice to have them work with the official release. If you are using our latest master code then changes there may mean they not longer work, as you saw. We had the Work In Progress PR, as you can see on qiskit tutorials to update notebooks for Aqua 0.5 ie the next version that will be released. The fork where we are doing this is was what you were pointed at. When the code is released, as the next official version, then the PR will be merged and the tutorials repo updated. Hope that helps explain things a little
maxiter = 100 optimizer = COBYLA(maxiter=maxiter)
var_form = RY(n, depth=1) #remove this line and run the line below it for QAOA var form
m = var_form.num_parameters
backend = Aer.get_backend('statevector_simulator')
this was the code from a repository:https://github.com/stefan-woerner/cvar_quantum_optimization.git
and while running the QAOA Var Form i am getting this error(after i comment Ry and use just QAOA.var_form or QAOA.Var_Form)
error::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::>
TypeError Traceback (most recent call last)
That code was done a few months ago. You could find a release of Qiskit from around that time and install that. If you are trying this on the latest code you will need to change the import since algorithms were re-organized into different categories since then
from qiskit.aqua.algorithms.adaptive.qaoa.var_form import QAOAVarForm
# var_form = QAOAVarForm(H, 1) # use this ansatz for CVaR-QAOA
to
from qiskit.aqua.algorithms.minimum_eigen_solvers.qaoa.var_form import QAOAVarForm
# var_form = QAOAVarForm(H, 1) # use this ansatz for CVaR-QAOA
The QAOA varform line does not need changing other than to remove the comment to use it. Your change to QAOA.var_form(H, 1)
seems to try to access a setter (property), which exists on QAOA to set in a given var_form directly, hence var_form(H,1) is seen as trying to pass (call) it parameters which is why you see the error you do.
The earlier code error was resolved but Now I received this new error; weighted Pauli operator -attribute error
Code:
alphas = [1.0, 0.25, 0.10] # confidence levels to be evaluated initial_point = np.random.rand(m) # same random initial set of parameters for all experiments objectives = {} # set of tested objective functions w.r.t. alpha for alpha in alphas: objectives[alpha] = Objective(var_form, H, offset, alpha, backend, optimal=optimal_value) optimizer.optimize(m, objectives[alpha].evaluate, initial_point=initial_point)
error is =========================>
AttributeError Traceback (most recent call last)
Try this
var_form = QAOAVarForm(H.to_opflow(), 1)
The operator logic was updated - this should update it to make it work.
I put a pull request to correct these errors if I manage to make a new version of it for the same dataset?
If the persons repository allows you to raise and issue or do a PR you can try and let them know. Clearly it would have worked against the code of the time when it was done. But things change over time and the operator form it now generates, the WeightedPauliOperator, is now a legacy function and it is expected to be deprecated and removed over time. Hence the fix above which converts it to the new form of operator.
thanks for the prompt response, this solution worked
Informations
What is the current behavior?
In the portfolio_optimization tutorial, running the very last cell (QAOA algorithm) results in a AttributeError: 'str' object has no attribute 'construct_circuit'. The only change I made was changing "seed_mapper=seed" to "seed_transpiler=seed".
Here is the resulting error:
Steps to reproduce the problem
Run the tutorial (making some minor fixes in imports as well), this is the very last cell
What is the expected behavior?
Having a functional cell
Suggested solutions