1

I'm trying to run the VQE algorithm using an Aer backend simulator. However, whenever I run the algorithm I Receive this error: "AttributeError: 'TwoLocal' object has no attribute 'set_max_evals_grouped'"

Could anyone explain what this error means and how I can fix It?

This is the code I am using:

driver = PySCFDriver(atom='Li .0 .0 .0; H .0 .0 1.5049', unit=UnitsType.ANGSTROM, charge=0, spin=0, basis='sto3g')



#create  second quantiesed operator 
es_problem= ElectronicStructureProblem(driver)
seconded_quanitsied_oprator= es_problem.second_q_ops() 
print(seconded_quanitsied_oprator)



#convert to qubit operator 


qubit_transformation = QubitConverter(JordanWignerMapper())
qubit_operator = qubit_transformation.convert(seconded_quanitsied_oprator[0])
print(qubit_operator) 


#set up simulator 
backend = BasicAer.get_backend('statevector_simulator')
quantum_instance=QuantumInstance(backend=backend)

# VEQ algothiums 
groundstate_energies = []
classical_optimizer = SLSQP(maxiter = 1000)


ansatz = TwoLocal(rotation_blocks='ry', entanglement_blocks='cz')


Vqe = VQE(qubit_operator,ansatz,SLSQP,quantum_instance )

1 Answers1

1

You are using VQE the old way (when it was in Aqua), so it doesn't work anymore. What you should do instead is this :

vqe = VQE(ansatz = ansatz,
          optimizer = SLSQP, 
          quantum_instance=quantum_instance)
vqe_result = vqe.compute_minimum_eigenvalue(qubit_operator)

Just in case, everything you need to know about how to move from Aqua is available here : https://qiskit.org/documentation/aqua_migration.html

Lena
  • 238
  • 1
  • 8
  • That seemed to work however it has now come up with a further error TypeError: set_max_evals_grouped() missing 1 required positional argument: 'limit' – shaun fuller Nov 24 '21 at 13:19
  • 2
    You need to ensure that you are not importing/using anything from aqua anymore. Use only the algorithms from qiskit.algorithms which is where the optimizers are located too now i.e. qiskit.algorithms.optimzers. When creating a minimal working example its good to have the imports so its runnable and it would be easy to see what was actually used. – Steve Wood Nov 24 '21 at 15:11
  • Thanks its all sorted now thanks for your help – shaun fuller Nov 25 '21 at 12:19