1
$\begingroup$

I would like to obtain the statevector of a QuantumCircuit using the simulator_statevector (and Qiskit) of the IBM Quantum Platform, in order to calculate an exact expectation value of an observable.

I managed to do that by using a finite amount of shots, but since the simulator uses the exact statevector, I wonder if there is a way to obtain that statevector.

$\endgroup$

1 Answer 1

1
$\begingroup$

The more modern and scalable way to get the expectation value of an observable is to use the Estimator primitive more on primitives here.

Local solution

Anyways, if you to get the statevector of some circuit follow the example below:

from qiskit import execute, Aer, QuantumCircuit
from qiskit.visualization import array_to_latex

# Here goes your circuit

backend = Aer.get_backend('statevector_simulator')
job = execute(qc, backend)
state = job.result().get_statevector()


array_to_latex(state, prefix="\\text{Statevector} = ")

Notice that get_statevector() is not a measurement.

On IBMQ cloud

I don't see a way to obtain an analytical expression of the final state vector. Moreover, by running a Bell circuit my own I realized that at the results obtained by job.result() there is nothing that could help. Although you can use job.result().get_counts() or the local solution which should work just fine.

Example

In advance make sure to load your IBM quantum experience account properly.

from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit import QuantumCircuit
from qiskit.visualization import plot_histogram

bell = QuantumCircuit(2)
bell.h(0)
bell.cx(0, 1)
bell.measure_all()

service = QiskitRuntimeService()
sim = service.get_backend("simulator_statevector")
job = sim.run(bell, shots=1000)
plot_histogram(job.result().get_counts())
$\endgroup$
4
  • $\begingroup$ I think that I was not clear on the question. "simulator_statevector" is a simulator that you can access with the cloud of IBM Quantum Platform. So I don't want to use Aer (i.e. local simulation on my device). The problem is that I don't know how to do something like "get_statevector" in that context. $\endgroup$
    – stopper
    Commented Jan 18 at 11:12
  • $\begingroup$ Oh ok I wasn't aware of that. $\endgroup$ Commented Jan 18 at 11:21
  • $\begingroup$ How did you get the "job" object in the cloud? $\endgroup$
    – stopper
    Commented Jan 18 at 14:31
  • $\begingroup$ On the example provided the type of job is qiskit_ibm_runtime.runtime_job.RuntimeJob. $\endgroup$ Commented Jan 18 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.