2
$\begingroup$

If the noise of the hardware is not considered, and measurements are performed at the end of the circuit, can the final state be obtained by performing linear algebra only once? And then, Monte Carlo simulations are used to obtain multiple samples?

I'm not sure if Qiskit supports this method. If it does, how can I write the code? I want to set a large shotnum, it's time-consuming right now.

$\endgroup$

1 Answer 1

2
$\begingroup$

You can certainly ask Qiskit to return you a statevector, a $2^n$ length vector giving the probability of each result. You can then get the samples yourself.

I wrote this helper function once.

from qiskit.quantum_info import Statevector
from qiskit import Aer

def get_statevector(qc, show=True) -> Statevector:
    sim = Aer.get_backend('aer_simulator')
    qc = qc.copy()
    qc.save_statevector()
    result = execute(qc, sim).result()
    vector = result.get_statevector()
    if show:
        display(Statevector(vector).draw('latex'))
    return vector
$\endgroup$
1
  • $\begingroup$ Thank you! I appreciate your help. $\endgroup$ Mar 9, 2023 at 19:43

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.