In order to calculate the exact expectation value of a Pauli operator in some state using local qasm_simulator, I do

psi = qiskit.aqua.operators.state_fns.CircuitStateFn( circuit )
expect = psi.adjoint().compose( weighted_pauli.to_opflow() ).compose( psi ).eval().real

I would like to run this calculation using ibmq_quantum_simulator. In all the examples I found online (see e.g. this one), ibmq_quantum_simulator is used to simulate sampling with some number of shots. How do I use it with shots = None, similarly to the code above?

  • $\begingroup$ You can't do shots=None to get the expectation value, this doesn't really make much sense; there are two ways to do the calculation of the expectation value: the exact way (the code you put) or with shot-based sampling, meaning using the simulator. I strongly advise you to look at this answer, quantumcomputing.stackexchange.com/questions/12080/…, really well-written about how to calculate the expectation value with Qiskit. As you can see the simulator is used for the second way of calculation. $\endgroup$
    – Lena
    Feb 15 at 16:49
  • $\begingroup$ You did not answer my question. The code I provided does the statevector calculation using my local CPU. How do I run this calculation using the ibmq_quantum_simulator? $\endgroup$
    – mavzolej
    Feb 15 at 17:42
  • 1
    $\begingroup$ @mavzolej why not just write your own function to calculate the expectation from the extracted counts you get from the experiment? $\endgroup$
    – KAJ226
    Feb 15 at 18:42
  • 1
    $\begingroup$ Well, by definition ibmq_qasm_simulator samples from the exact probability distribution, which is probably calculated using the statevector representation. I was hoping I can access it, but I don't know if it is possible... $\endgroup$
    – mavzolej
    Feb 15 at 18:54
  • 1
    $\begingroup$ (This page)[quantum-computing.ibm.com/docs/manage/simulator/] says that the underlying code of imbq_qasm_simulator is similar to that of qasm_simulator. And in qasm_simulator one can choose method = statevector. $\endgroup$
    – mavzolej
    Feb 15 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.