Closed chMoussa closed 6 years ago
Hey @chMoussa.
This occurs when one does not have TNQVM installed and does not specify the Accelerator to run with. In your code you get reference to the IBM Accelerator and use it to compile the ansatz, but you do not indicate that you are going to use it in the vqe.execute()
method.
Try adding 'accelerator':'ibm' to the vqe.execute kwargs dictionary.
vqeResult = vqe.execute(H2, **{'task':'vqe', 'ansatz':ansatzH2, 'accelerator':'ibm'})
Or before this call, call
xacc.setOption('accelerator', 'ibm')
Note that the 'vqe-params' key is for setting the state prep ansatz parameters.
It worked with the setOption with 2 VQE calls. You still have errors about setExpectationvalueZ not implemented.
I would like to see if this goes away after updating to the new xacc-ibm plugin. @czhao39 is going to try this script with his updated xacc-ibm wheel.
@chMoussa I have uploaded an updated xacc-ibm wheel to PyPi. You can now run
$ python -m pip install --upgrade xacc-ibm
Let us know if that gets rid of your bug.
Note you should see it upgrade to version 0.1.1
Now working well. Here is a screenshot of the 155th iteration.
Hello,
I get this error when trying VQE on a simple example by setting a IBM accelerator.
Here is the example code :
import pyxaccvqe as vqe import pyxacc as xacc from pyxaccvqe import PauliOperator
xacc.Initialize(["--compiler","quil"]) accelerator = "ibm" backend = "ibmq_qasm_simulator"
qpu = xacc.getAccelerator(accelerator) xacc.setOption(accelerator+"-backend",backend)
Getting Ansatz kernel
srcH2 = """qpu ansatz(AcceleratorBuffer, double t0) { X 0 RY(t0) 1 CNOT 1 0 }"""
ansatzH2 = xacc.compileKernel(qpu,srcH2)
Defining problem
bond_length = 0.7474 H2 = PauliOperator(5.906709445) + \ PauliOperator({0:'X',1:'X'}, -2.1433) + \ PauliOperator({0:'Y',1:'Y'}, -2.1433) + \ PauliOperator({0:'Z'}, .21829) + \ PauliOperator({1:'Z'}, -6.125) print(H2)
Executing
vqeResult = vqe.execute(H2,**{"task":"vqe", "vqe_params":str(bond_length),"ansatz":ansatzH2})
print('(Optimal Angle, Energy) = (', vqeResult.angles,',', vqeResult.energy, ')') print('Number of QPU Calls = ', vqeResult.nQpuCalls) print('Number of VQE Iterations = ', vqeResult.vqeIterations)