I create an instance of a OpflowQNN with the following:
qnn = OpflowQNN(operator=~StateFn(Z ^ Z ^ I ^ I) @ StateFn(circuit),
input_params=input_params,
weight_params=weights,
quantum_instance=qi
)
where circuit is a qiskit.circuit.QuantumCircuit operating on 4 qubits.
What I am trying to achieve is to only measure the expectation value on qubit 2 and 3 in the Z-basis when running the forward pass. I don't need the values for qubits 0 and 1.
I want the expectation value for both qubits seperately, which leads to an output shape of (2,) in the forward pass.
What I tried to do is to apply the Pauli Z operators to the 2nd and 3rd qubit only, as you can see in the code snippet above.
But still the output of the forward pass has shape (1,). I am currently struggeling to understand what exacly these Observables do. I also don't really get what the output of the forward pass in the OpflowQNN is. My guess was some summed up expectation values, but I am not quite sure about it.
Another thing I tried with the work-in-progress version of qiskit that I built from source (Otherwise this would not work):
operator=ListOp([~StateFn(Z ^ I ^ I ^ I), ~StateFn(I ^ Z ^ I ^ I)]) @ StateFn(circuit)
This gives me an array of shape (2,) in the forward pass, but I am not sure if this is really the right way to calculate the expectation values on qubit 2 and 3.