Hello, everyone! I am starting a VQE project in Pennylane and I have encountered a problem with the cost function. I defined my parameterized circuit as:
L = 4
N = 2
def circuit(params, wires):
pl.BasisState(pl.qchem.hf_state(N,2*L), wires=wires)
for i in range(0,2*L,4):
pl.DoubleExcitation(params[int(i/4)], wires=[i,i+1,i+2,i+3])
such that in this case the length of params is 2. But after defining cost_fn:
dev = pl.device("default.qubit",wires=2*L)
cost_fn = pl.ExpvalCost(circuit, hamiltonian, dev)
I cannot call cost_fn as:
cost_fn([0,0])
as I get an error regarding array shapes:
ValueError: shapes (2,) and (256,) not aligned: 2 (dim 0) != 256 (dim 0)
What did I do wrong? The hamiltonian is a bit long so I will just paste the output from the notebook:
<Hamiltonian: terms=61, wires=[0, 1, 2, 3, 4, 5, 6, 7]>