2

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?

glS
  • 24,708
  • 5
  • 34
  • 108
mavzolej
  • 1,921
  • 7
  • 17
  • 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, https://quantumcomputing.stackexchange.com/questions/12080/evaluating-expectation-values-of-operators-in-qiskit/12210#12210, 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. – Lena Feb 15 '21 at 16:49
  • 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? – mavzolej Feb 15 '21 at 17:42
  • 1
    @mavzolej why not just write your own function to calculate the expectation from the extracted counts you get from the experiment? – KAJ226 Feb 15 '21 at 18:42
  • Which counts?.. I want to do the statevector calculation, which does not involve any counts, and only uses the statevector representation of a quantum state and the unitary matrix representation of the quantum circuit. – mavzolej Feb 15 '21 at 18:44
  • @mavzolej I thought ibmq_qasm_simulator can only do shot based simulation... can you actually extract the statevector from it? Didn't know that was possible. – KAJ226 Feb 15 '21 at 18:51
  • 1
    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... – mavzolej Feb 15 '21 at 18:54
  • 1
    (This page)[https://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. – mavzolej Feb 15 '21 at 18:58

0 Answers0