Closed KetpuntoG closed 5 months ago
Example:
from qiskit import IBMQ
import pennylane as qml
from pennylane import numpy as np
from pennylane_qiskit import upload_vqe_runner, vqe_runner
provider = IBMQ.enable_account(*TOKEN*)
program_id = upload_vqe_runner(hub="ibm-q", group="open", project="main")
H = qml.Hamiltonian([0.5, 0.5, 0.5, 0.5],\
[qml.Identity(0) @ qml.Identity(1),\
qml.PauliX(0) @ qml.PauliX(1),\
qml.PauliY(0) @ qml.PauliY(1),\
qml.PauliZ(0) @ qml.PauliZ(1)])
def vqe_circuit(params):
a, b = params
qml.RX(a, 0)
qml.RZ(b, 0)
qml.RX(a, 1)
qml.RZ(b, 1)
job = vqe_runner(
program_id=program_id,
backend="ibmq_qasm_simulator",
hamiltonian=H,
ansatz=vqe_circuit,
x0=np.random.randn(2),
shots=8192,
optimizer="SPSA",
optimizer_config={"maxiter": 100},
kwargs={"hub": "ibm-q", "group": "open", "project": "main"},
)
This gives UserWarning: In order to match the tape expansion, the number of parameters has been changed
. Moreover:
job.result()
fun: 0.0003662109375
message: 'Optimization terminated successfully.'
nfev: 300
nit: 100
success: True
x: array([3.15633508, 6.56843918, 6.30372469, 7.8613945 ])
Instead of optimizing over the two parameters (a and b), reusing each twice, it's optimized over four, treating each use of a parameter separately.
Closing because Qiskit has removed the VQE runner, so it is no longer part of the plugin.
Describe the bug (Bug found by Matthew Weiss)
When I use the same parameter twice within an anstaz, when I send it to the vqe_runner, they are optimized separately, so the equal relationship between them is not maintained.
Reason for the behavior
the quantum circuit is transformed to a tape (concrete values are assigned)