# Using opflow, CircuitStateFn and CircuitSampler, is there any way to submit the expectation values for multiple, distinct states in the same IBMQ job

I am trying to find the expectation of a Hamiltonian w.r.t different states. I am creating my states using CircuitStateFn. Then, I am using ListOp() of CircuitStateFn. But this is giving me an error - "ListOp expecting objects of type OperatorBase, got CircuitStateFn". My code looks like -

from qiskit.aqua.operators import PauliExpectation, CircuitSampler, CircuitStateFn
from qiskit.aqua import QuantumInstance
from qiskit import Aer
from matplotlib import pyplot as plt
from qiskit.opflow import ListOp

H = - (X^X^I^I) -(I^X^X^I) - (I^I^X^X)- (X^I^I^X)

state=[]
backend = Aer.get_backend('qasm_simulator')
qp=QuantumInstance(backend,shots=1024)

#State 1
q = QuantumRegister(4,'q')
qc1 = QuantumCircuit(q)
qc1.x(0)
qc1.h(1)
psi1 = CircuitStateFn(qc)
state.append(psi1)

#State 2
q = QuantumRegister(4,'q')
qc2 = QuantumCircuit(q)
qc2.h(2)
qc2.h(3)
psi2 = CircuitStateFn(qc)
state.append(psi2)

#State 3
q = QuantumRegister(4,'q')
qc3 = QuantumCircuit(q)
qc3.h(2)
qc3.cx(2,3)
psi3 = CircuitStateFn(qc)
state.append(psi3)

measurable_expression = StateFn(H, is_measurement=True).compose(ListOp(state))
# convert to expectation value
expectation=PauliExpectation().convert(measurable_expression)
sampler=CircuitSampler(qp).convert(expectation)

• Hello! I notice you use Aqua, I strongly suggest you migrate to the newest version of Qiskit since Aqua has been deprecated for a few months now and is not updated anymore. To help you do that check this migration guide : qiskit.org/documentation/aqua_migration.html
– Lena
Nov 10 at 12:46